aboutsummaryrefslogtreecommitdiffstats
path: root/pkgid.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkgid.go')
-rw-r--r--pkgid.go109
1 files changed, 68 insertions, 41 deletions
diff --git a/pkgid.go b/pkgid.go
index 95b6303..1268568 100644
--- a/pkgid.go
+++ b/pkgid.go
@@ -1,10 +1,13 @@
package lulu
import (
- "encoding/json"
+ "bytes"
+ "encoding"
"fmt"
)
+//go:generate go run github.com/yawnak/string-enumer -t TrimSize -t ColorType -t Quality -t Binding -t Paper -t Finish -t Linen -t Foil --text -o ./pkgid_gen.go .
+
// PkgId is a pod_package_id which represents the manufacturing options
// of a printable.
type PkgId struct {
@@ -18,8 +21,32 @@ type PkgId struct {
Foil
}
-func (p PkgId) MarshalJSON() ([]byte, error) {
- return json.Marshal(fmt.Sprintf("%s.%s.%s.%s.%s.%s%s%s", p.TrimSize, p.ColorType, p.Quality, p.Binding, p.Paper, p.Finish, p.Linen, p.Foil))
+func (p PkgId) MarshalText() ([]byte, error) {
+ return []byte(fmt.Sprintf("%s.%s.%s.%s.%s.%s%s%s", p.TrimSize, p.ColorType, p.Quality, p.Binding, p.Paper, p.Finish, p.Linen, p.Foil)), nil
+}
+
+func (p *PkgId) UnmarshalText(text []byte) error {
+ s := string(text)
+ parts := bytes.Split(text, []byte("."))
+ if len(parts) != 6 {
+ return fmt.Errorf("malformed pod_package_id %q: has %d dot-separated fields; want 6", s, len(parts))
+ }
+ cover := parts[5]
+ if len(cover) != 3 {
+ return fmt.Errorf("malformed pod_package_id %q: finish/linen/foil suffix must be 3 characters", s)
+ }
+
+ for i, field := range []encoding.TextUnmarshaler{&p.TrimSize, &p.ColorType, &p.Quality, &p.Binding, &p.Paper} {
+ if err := field.UnmarshalText(parts[i]); err != nil {
+ return err
+ }
+ }
+ for i, field := range []encoding.TextUnmarshaler{&p.Finish, &p.Linen, &p.Foil} {
+ if err := field.UnmarshalText([]byte{cover[i]}); err != nil {
+ return err
+ }
+ }
+ return nil
}
// TrimSize is the final dimensions of the pages after the bleed margins
@@ -28,21 +55,21 @@ type TrimSize string
const (
Pocketbook TrimSize = "0425X0687"
- Novella = "0500X0800"
- Digest = "0550X0850"
- A5 = "0583X0827"
- UsTrade = "0600X0900"
- Royal = "0614X0921"
- Comic = "0663X1025"
- SmallSquare = "0750X0750"
- Executive = "0700X1000"
- CrownQuatro = "0744X0968"
- Square = "0850X0850"
- A4 = "0827X1169"
- UsLetter = "0850X1100"
- Landscape = "0900X0700"
- UsLetterLandscape = "1100X0850"
- A4Landscape = "1169X0827"
+ Novella TrimSize = "0500X0800"
+ Digest TrimSize = "0550X0850"
+ A5 TrimSize = "0583X0827"
+ UsTrade TrimSize = "0600X0900"
+ Royal TrimSize = "0614X0921"
+ Comic TrimSize = "0663X1025"
+ SmallSquare TrimSize = "0750X0750"
+ Executive TrimSize = "0700X1000"
+ CrownQuatro TrimSize = "0744X0968"
+ Square TrimSize = "0850X0850"
+ A4 TrimSize = "0827X1169"
+ UsLetter TrimSize = "0850X1100"
+ Landscape TrimSize = "0900X0700"
+ UsLetterLandscape TrimSize = "1100X0850"
+ A4Landscape TrimSize = "1169X0827"
)
// ColorType is the color mode of the printer.
@@ -50,7 +77,7 @@ type ColorType string
const (
Mono ColorType = "BW"
- Color = "FC"
+ Color ColorType = "FC"
)
// Quality is the print quality.
@@ -58,18 +85,18 @@ type Quality string
const (
Premium Quality = "PRE"
- Standard = "STD"
+ Standard Quality = "STD"
)
type Binding string
const (
Perfect Binding = "PB"
- Coil = "CO"
- SaddleStitch = "SS"
- CaseWrap = "CW"
- LinenWrap = "LW"
- WireO = "WO"
+ Coil Binding = "CO"
+ SaddleStitch Binding = "SS"
+ CaseWrap Binding = "CW"
+ LinenWrap Binding = "LW"
+ WireO Binding = "WO"
)
// Paper is the weight/thickness and hue of the paper.
@@ -77,10 +104,10 @@ type Paper string
const (
P60UncoatedWhite Paper = "060UW444"
- P60UncoatedCream = "060UC444"
- P70CoatedWhite = "070CW460"
- P80CoatedWhite = "080CW444"
- P100CoatedWhite = "100CW"
+ P60UncoatedCream Paper = "060UC444"
+ P70CoatedWhite Paper = "070CW460"
+ P80CoatedWhite Paper = "080CW444"
+ P100CoatedWhite Paper = "100CW"
)
// Finish is the surface finish of the cover.
@@ -88,8 +115,8 @@ type Finish string
const (
Gloss Finish = "G"
- Matte = "M"
- Unlaminated = "U"
+ Matte Finish = "M"
+ Unlaminated Finish = "U"
)
// Linen is the color of the linen-wrapped cover, if applicable.
@@ -97,13 +124,13 @@ type Linen string
const (
RedLinen Linen = "R"
- NavyLinen = "N"
- BlackLinen = "B"
- GrayLinen = "G"
- TanLinen = "T"
- ForestLinen = "F"
- InteriorCoverPrint = "I"
- NoLinen = "X"
+ NavyLinen Linen = "N"
+ BlackLinen Linen = "B"
+ GrayLinen Linen = "G"
+ TanLinen Linen = "T"
+ ForestLinen Linen = "F"
+ InteriorCoverPrint Linen = "I"
+ NoLinen Linen = "X"
)
// Foil is the color of the foil stamping, if applicable.
@@ -111,7 +138,7 @@ type Foil string
const (
GoldFoil Foil = "G"
- BlackFoil = "B"
- WhiteFoil = "W"
- NoFoil = "X"
+ BlackFoil Foil = "B"
+ WhiteFoil Foil = "W"
+ NoFoil Foil = "X"
)