usps_flags 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -11
- data/.travis.yml +1 -1
- data/Gemfile.lock +5 -2
- data/README.md +6 -0
- data/lib/usps_flags.rb +35 -44
- data/lib/usps_flags/config.rb +89 -87
- data/lib/usps_flags/core.rb +44 -42
- data/lib/usps_flags/core/ensign.rb +53 -49
- data/lib/usps_flags/core/field.rb +96 -92
- data/lib/usps_flags/core/footer.rb +9 -5
- data/lib/usps_flags/core/headers.rb +58 -48
- data/lib/usps_flags/core/icons.rb +11 -7
- data/lib/usps_flags/core/icons/anchor.rb +62 -56
- data/lib/usps_flags/core/icons/binoculars.rb +21 -15
- data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
- data/lib/usps_flags/core/icons/star.rb +21 -15
- data/lib/usps_flags/core/icons/trident.rb +136 -127
- data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
- data/lib/usps_flags/core/icons/trumpet.rb +34 -28
- data/lib/usps_flags/core/pennant.rb +50 -46
- data/lib/usps_flags/core/trident_spec.rb +135 -131
- data/lib/usps_flags/core/trident_specs.rb +11 -7
- data/lib/usps_flags/core/trident_specs/base.rb +36 -26
- data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
- data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
- data/lib/usps_flags/core/trident_specs/header.rb +56 -50
- data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
- data/lib/usps_flags/core/trident_specs/long.rb +41 -25
- data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
- data/lib/usps_flags/core/trident_specs/short.rb +30 -156
- data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
- data/lib/usps_flags/core/tridents.rb +54 -50
- data/lib/usps_flags/core/us.rb +40 -44
- data/lib/usps_flags/core/wheel.rb +7 -3
- data/lib/usps_flags/errors.rb +25 -23
- data/lib/usps_flags/generate.rb +111 -107
- data/lib/usps_flags/generate/flag.rb +160 -157
- data/lib/usps_flags/generate/generator_methods.rb +139 -0
- data/lib/usps_flags/generate/helper_methods.rb +88 -0
- data/lib/usps_flags/helpers.rb +163 -165
- data/lib/usps_flags/helpers/builders.rb +92 -85
- data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
- data/lib/usps_flags/helpers/valid_flags.rb +45 -41
- data/lib/usps_flags/rational.rb +35 -0
- data/spec/usps_flags/config_spec.rb +17 -10
- data/spec/usps_flags/core_spec.rb +31 -31
- data/spec/usps_flags/generate_spec.rb +76 -73
- data/spec/usps_flags/helpers_spec.rb +8 -8
- data/spec/usps_flags/rational_spec.rb +17 -0
- data/spec/usps_flags_spec.rb +19 -21
- data/usps_flags.gemspec +7 -6
- metadata +34 -10
- data/lib/rational.rb +0 -39
- data/lib/usps_flags/generate/private.rb +0 -199
- data/spec/rational_spec.rb +0 -19
data/lib/usps_flags/core.rb
CHANGED
@@ -4,60 +4,62 @@
|
|
4
4
|
#
|
5
5
|
# These methods should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
def self.trident_spec(fly: 24, unit: 'in', scaled_border: false)
|
10
|
+
USPSFlags::Core::TridentSpec.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def self.headers(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
|
14
|
+
USPSFlags::Core::Headers.new(width: width, height: height, pennant: pennant, scale: scale, title: title).svg
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def self.footer
|
18
|
+
USPSFlags::Core::Footer.new.svg
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def self.field(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
|
22
|
+
USPSFlags::Core::Field.new(style: style, color: color, fly: fly).svg
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def self.trident(type, color: :blue, field_color: nil)
|
26
|
+
USPSFlags::Core::Icons::Trident.new(type, color: color, field_color: field_color).svg
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def self.anchor(color = :red)
|
30
|
+
USPSFlags::Core::Icons::Anchor.new(color: color).svg
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def self.lighthouse
|
34
|
+
USPSFlags::Core::Icons::Lighthouse.new.svg
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def self.binoculars(type = :d)
|
38
|
+
USPSFlags::Core::Icons::Binoculars.new(type: type).svg
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def self.trumpet(type = :s)
|
42
|
+
USPSFlags::Core::Icons::Trumpet.new(type: type).svg
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def self.pennant(type = 'cruise')
|
46
|
+
USPSFlags::Core::Pennant.new(type: type).svg
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
def self.ensign
|
50
|
+
USPSFlags::Core::Ensign.new.svg
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def self.star
|
54
|
+
USPSFlags::Core::Icons::Star.new.svg
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
def self.wheel
|
58
|
+
USPSFlags::Core::Wheel.new.svg
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
def self.us
|
62
|
+
USPSFlags::Core::US.new.svg
|
63
|
+
end
|
62
64
|
end
|
63
65
|
end
|
@@ -4,65 +4,69 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
<g transform="
|
15
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
class Ensign
|
10
|
+
def svg
|
11
|
+
<<~SVG
|
12
|
+
#{stripes}
|
13
|
+
#{canton}
|
14
|
+
<g transform="scale(0.3675)">
|
15
|
+
<g transform="translate(1200, 600)">
|
16
|
+
<g transform="rotate(-45, 693, 1500)">
|
17
|
+
#{USPSFlags::Core::Icons::Anchor.new(color: :white).svg}
|
18
|
+
</g>
|
19
|
+
</g>
|
16
20
|
</g>
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
SVG
|
21
|
-
end
|
21
|
+
#{star_circle}
|
22
|
+
SVG
|
23
|
+
end
|
22
24
|
|
23
|
-
private
|
25
|
+
private
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def stripes
|
28
|
+
(0..12).map do |index|
|
29
|
+
index.odd? ? white_stripe(index) : blue_stripe(index)
|
30
|
+
end.join
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
def canton
|
34
|
+
<<~SVG
|
35
|
+
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY * 6 / 13}" height="1000" fill="#{USPSFlags::Config::RED}" />
|
36
|
+
SVG
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def white_stripe(index)
|
40
|
+
<<~SVG
|
41
|
+
<rect x="#{USPSFlags::Config::BASE_FLY * index / 13}" y="0" width="#{USPSFlags::Config::BASE_FLY / 13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
|
42
|
+
SVG
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def blue_stripe(index)
|
46
|
+
<<~SVG
|
47
|
+
<rect x="#{USPSFlags::Config::BASE_FLY * index / 13}" y="0" width="#{USPSFlags::Config::BASE_FLY / 13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
|
48
|
+
SVG
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
def star_circle
|
52
|
+
svg = +''
|
51
53
|
|
52
|
-
|
54
|
+
(0..13).each { |i| svg << rotated_star(i * (360.0 / 13)) }
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
+
svg
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
def rotated_star(rotation)
|
60
|
+
<<~SVG
|
61
|
+
<g transform="scale(0.375)">
|
62
|
+
<g transform="translate(1885, 465)">
|
63
|
+
<g transform="rotate(#{rotation}, 0, 900)">
|
64
|
+
#{USPSFlags::Core.star}
|
65
|
+
</g>
|
66
|
+
</g>
|
63
67
|
</g>
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
SVG
|
69
|
+
end
|
70
|
+
end
|
67
71
|
end
|
68
72
|
end
|
@@ -4,110 +4,114 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
class Field
|
10
|
+
def initialize(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
|
11
|
+
@style = style
|
12
|
+
@fly = fly
|
13
|
+
border = color == :white
|
14
|
+
@color_code, @past_mid_color, @past_tail_color = send("#{color}_colors")
|
15
|
+
@border_svg = if border
|
16
|
+
"stroke=\"#000000\" stroke-width=\"#{USPSFlags::Config::BASE_FLY / 600}\" "
|
17
|
+
else
|
18
|
+
''
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
@hoist = (@fly * 2) / 3
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
def svg
|
25
|
+
case @style
|
26
|
+
when :regular
|
27
|
+
regular_field
|
28
|
+
when :swallowtail
|
29
|
+
swallowtail_field
|
30
|
+
when :past
|
31
|
+
past_field
|
32
|
+
end
|
33
|
+
end
|
32
34
|
|
33
|
-
private
|
35
|
+
private
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
def white_colors
|
38
|
+
['#FFFFFF', USPSFlags::Config::BLUE, USPSFlags::Config::RED]
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def red_colors
|
42
|
+
[USPSFlags::Config::RED, '#FFFFFF', USPSFlags::Config::BLUE]
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
def blue_colors
|
46
|
+
[USPSFlags::Config::BLUE, '#FFFFFF', USPSFlags::Config::RED]
|
47
|
+
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
def regular_field
|
50
|
+
<<~SVG
|
51
|
+
<path d="M 0 0
|
52
|
+
l #{@fly} 0
|
53
|
+
l 0 #{@hoist}
|
54
|
+
l -#{@fly} 0
|
55
|
+
l 0 -#{@hoist}
|
56
|
+
" fill="#{@color_code}" #{@border_svg}/>
|
57
|
+
SVG
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
def swallowtail_field
|
61
|
+
<<~SVG
|
62
|
+
<path d="M #{USPSFlags::Config::BASE_FLY / 1200} #{USPSFlags::Config::BASE_FLY / 1800}
|
63
|
+
l #{@fly} #{@hoist / 6}
|
64
|
+
l -#{@fly / 5} #{@hoist / 3}
|
65
|
+
l #{@fly / 5} #{@hoist / 3}
|
66
|
+
l -#{@fly} #{@hoist / 6} z
|
67
|
+
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
68
|
+
SVG
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
71
|
+
def past_field
|
72
|
+
<<~SVG
|
73
|
+
<g transform="translate(#{USPSFlags::Config::BASE_FLY / 1200}, #{USPSFlags::Config::BASE_FLY / 1800})">
|
74
|
+
<path d="M 0 #{USPSFlags::Config::BASE_FLY / 600} #{past_line_one}" fill="#{@color_code}" />
|
75
|
+
<path d="M #{@fly / 2} #{@hoist / 12} #{past_line_two}" fill="#{@past_mid_color}" />
|
76
|
+
<path d="M #{@fly * 3 / 4} #{@hoist * 3 / 24} #{past_line_three}" fill="#{@past_tail_color}" />
|
77
|
+
<path d="M 0 0 #{past_line_four} z" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
78
|
+
</g>
|
79
|
+
SVG
|
80
|
+
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
82
|
+
def past_line_one
|
83
|
+
<<~SVG
|
84
|
+
l #{@fly / 2} #{@hoist / 12}
|
85
|
+
l 0 #{@hoist * 10 / 12}
|
86
|
+
l -#{@fly / 2} #{@hoist / 12}
|
87
|
+
SVG
|
88
|
+
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
def past_line_two
|
91
|
+
<<~SVG
|
92
|
+
l #{@fly / 4} #{@hoist / 24}
|
93
|
+
l 0 #{@hoist * 9 / 12}
|
94
|
+
l -#{@fly / 4} #{@hoist / 24}
|
95
|
+
SVG
|
96
|
+
end
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
98
|
+
def past_line_three
|
99
|
+
<<~SVG
|
100
|
+
l #{@fly / 4} #{@hoist / 24}
|
101
|
+
l -#{@fly / 5} #{@hoist / 3}
|
102
|
+
l #{@fly / 5} #{@hoist / 3}
|
103
|
+
l -#{@fly / 4} #{@hoist / 24}
|
104
|
+
SVG
|
105
|
+
end
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
107
|
+
def past_line_four
|
108
|
+
<<~SVG
|
109
|
+
l #{@fly} #{@hoist / 6}
|
110
|
+
l -#{@fly / 5} #{@hoist / 3}
|
111
|
+
l #{@fly / 5} #{@hoist / 3}
|
112
|
+
l -#{@fly} #{@hoist / 6}
|
113
|
+
SVG
|
114
|
+
end
|
115
|
+
end
|
112
116
|
end
|
113
117
|
end
|
@@ -4,10 +4,14 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
class Footer
|
10
|
+
def svg
|
11
|
+
<<~SVG
|
12
|
+
</svg>
|
13
|
+
SVG
|
14
|
+
end
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|