usps_flags 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -4,105 +4,112 @@
|
|
4
4
|
#
|
5
5
|
# These methods should never need to be called directly, except when designing new flags.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Helpers
|
9
|
+
class Builders
|
10
|
+
class << self
|
11
|
+
# Displays an overlay grid with regularly spaced locator markers.
|
12
|
+
#
|
13
|
+
# This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
|
14
|
+
# @private
|
15
|
+
def grid(width: USPSFlags::Config::BASE_FLY, height: USPSFlags::Config::BASE_HOIST)
|
16
|
+
@width = width
|
17
|
+
@height = height
|
18
|
+
@stroke_width = @width / 600
|
19
|
+
"#{circles}#{horizontal_lines}#{vertical_lines}#{diagonal_lines}"
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
# Displays an overlay indicator of concentric circles and radiating lines.
|
23
|
+
#
|
24
|
+
# This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
|
25
|
+
# @private
|
26
|
+
def locator
|
27
|
+
<<~SVG
|
28
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY * 2}" fill="#000000" fill-opacity="0.4" />
|
29
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY}" fill="#333333" fill-opacity="0.4" />
|
30
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 2}" fill="#666666" fill-opacity="0.4" />
|
31
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 4}" fill="#999999" fill-opacity="0.4" />
|
32
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 8}" fill="#CCCCCC" fill-opacity="0.4" />
|
33
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 16}" fill="#FFFFFF" fill-opacity="0.4" />
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="-#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
36
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
37
|
+
<line x1="0" y1="#{USPSFlags::Config::BASE_HOIST}" x2="0" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
38
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="0" x2="#{USPSFlags::Config::BASE_FLY}" y2="0" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY / 30}" height="#{USPSFlags::Config::BASE_FLY / 30}" fill="#333333" fill-opacity="0.6" />
|
41
|
+
SVG
|
42
|
+
end
|
41
43
|
|
42
|
-
|
44
|
+
private
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
def circles
|
47
|
+
<<~SVG
|
48
|
+
#{pos_circle(0, 0)}
|
49
|
+
#{pos_circle(@width, 0)}
|
50
|
+
#{pos_circle(@width, @height)}
|
51
|
+
#{pos_circle(0, @height)}
|
52
|
+
<circle cx="#{@width * 1 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
|
53
|
+
<circle cx="#{@width * 3 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
|
54
|
+
#{radial_circles}
|
55
|
+
SVG
|
56
|
+
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
def radial_circles
|
59
|
+
<<~SVG
|
60
|
+
#{radial_circle(1, @width / 60)}
|
61
|
+
#{radial_circle(2, @width / 60)}
|
62
|
+
#{radial_circle(2, @width / 75)}
|
63
|
+
#{radial_circle(2, @width / 100)}
|
64
|
+
#{radial_circle(3, @width / 60)}
|
65
|
+
SVG
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
def pos_circle(cx, cy)
|
69
|
+
<<~SVG
|
70
|
+
<circle cx="#{cx}" cy="#{cy}" r="#{@width / 60}" fill="#000000" fill-opacity="0.4" />
|
71
|
+
SVG
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
def radial_circle(index, radius)
|
75
|
+
<<~SVG
|
76
|
+
<circle cx="#{@width / 2}" cy="#{@height * index / 4}" r="#{radius}" fill="#999999" fill-opacity="0.4" />
|
77
|
+
SVG
|
78
|
+
end
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
def horizontal_lines
|
81
|
+
(0..4).map { |index| horizontal_line(index) }.join
|
82
|
+
end
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
def horizontal_line(index)
|
85
|
+
<<~SVG
|
86
|
+
<line x1="0" y1="#{@height * index / 4}" x2="#{@width}" y2="#{@height * index / 4}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
|
87
|
+
SVG
|
88
|
+
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
|
90
|
+
def vertical_lines
|
91
|
+
(0..6).map { |index| vertical_line(index) }.join
|
92
|
+
end
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
def vertical_line(index)
|
95
|
+
<<~SVG
|
96
|
+
<line y1="0" x1="#{@width * index / 6}" y2="#{@height}" x2="#{@width * index / 6}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
|
97
|
+
SVG
|
98
|
+
end
|
97
99
|
|
98
|
-
|
99
|
-
|
100
|
-
|
100
|
+
def diagonal_lines
|
101
|
+
diagonal_line(2, 1, 3, 2) +
|
102
|
+
diagonal_line(3, 2, 2, 3) +
|
103
|
+
diagonal_line(2, 3, 1, 2) +
|
104
|
+
diagonal_line(1, 2, 2, 1)
|
105
|
+
end
|
101
106
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
107
|
+
def diagonal_line(a, b, c, d)
|
108
|
+
<<~SVG
|
109
|
+
<line x1="#{@width * a / 4}" y1="#{@height * b / 4}" x2="#{@width * c / 4}" y2="#{@height * d / 4}" stroke="#999999" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
|
110
|
+
SVG
|
111
|
+
end
|
112
|
+
end
|
106
113
|
end
|
107
114
|
end
|
108
115
|
end
|
@@ -4,130 +4,134 @@
|
|
4
4
|
#
|
5
5
|
# These methods should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Helpers
|
9
|
+
class SpecArrows
|
10
|
+
class << self
|
11
|
+
# Creates a vertical arrow for the trident spec sheet.
|
12
|
+
#
|
13
|
+
# This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
|
14
|
+
# @private
|
15
|
+
def vertical(x, top, bottom, **options)
|
16
|
+
options = defaults.merge(options)
|
17
|
+
|
18
|
+
load_common_config(options[:fly])
|
19
|
+
label, label_fraction = get_labels(bottom, top)
|
20
|
+
options = options.merge(x: x, top: top, bottom: bottom, label: label, label_fraction: label_fraction)
|
21
|
+
|
22
|
+
vertical_svg_group(options)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Creates a horizontal arrow for the trident spec sheet.
|
26
|
+
#
|
27
|
+
# This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
|
28
|
+
# @private
|
29
|
+
def horizontal(y, left, right, **options)
|
30
|
+
options = defaults(:h).merge(options)
|
31
|
+
|
32
|
+
load_common_config(options[:fly])
|
33
|
+
label, label_fraction = get_labels(right, left)
|
34
|
+
options = options.merge(y: y, left: left, right: right, label: label, label_fraction: label_fraction)
|
35
|
+
|
36
|
+
horizontal_svg_group(options)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def defaults(mode = :v)
|
42
|
+
{
|
43
|
+
pointer_top: nil, pointer_bottom: nil, pointer_left: nil, pointer_right: nil, fly: nil,
|
44
|
+
unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / (mode == :v ? 120 : 45)),
|
45
|
+
label_offset_x: 0, label_offset_y: 0, label_align: (mode == :v ? 'left' : 'middle')
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def vertical_svg_group(options)
|
50
|
+
svg = +''
|
51
|
+
svg << arrow_pointer(options) unless options[:pointer_top].nil?
|
52
|
+
svg << arrow_pointer(options) unless options[:pointer_bottom].nil?
|
53
|
+
svg << vertical_svg(options)
|
54
|
+
svg
|
55
|
+
end
|
56
|
+
|
57
|
+
def vertical_svg(options)
|
58
|
+
<<~SVG
|
59
|
+
<path d="#{vertical_svg_path(options)}" fill="none" />
|
60
|
+
<g>
|
61
|
+
<style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
|
62
|
+
#{vertical_svg_text(options)}
|
63
|
+
</g>
|
64
|
+
SVG
|
65
|
+
end
|
66
|
+
|
67
|
+
def vertical_svg_path(options)
|
68
|
+
<<~SVG
|
69
|
+
M#{options[:x]} #{options[:top]} l #{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l -#{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l 0 #{options[:bottom] - options[:top]} l #{@arrow_size} -#{@arrow_size} M#{options[:x]} #{options[:bottom]} l -#{@arrow_size} -#{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}
|
70
|
+
SVG
|
71
|
+
end
|
72
|
+
|
73
|
+
def vertical_svg_text(options)
|
74
|
+
<<~SVG
|
75
|
+
<text x="#{options[:x] + options[:label_offset]}" y="#{(options[:top] + options[:bottom]) / 2 + (USPSFlags::Config::BASE_HOIST / 150) + options[:label_offset_y]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
|
76
|
+
SVG
|
77
|
+
end
|
78
|
+
|
79
|
+
def horizontal_svg_group(options)
|
80
|
+
svg = +''
|
81
|
+
svg << arrow_pointer(options) unless options[:pointer_left].nil?
|
82
|
+
svg << arrow_pointer(options) unless options[:pointer_right].nil?
|
83
|
+
svg << horizontal_svg(options)
|
84
|
+
svg
|
85
|
+
end
|
86
|
+
|
87
|
+
def horizontal_svg(options)
|
88
|
+
<<~SVG
|
89
|
+
<path d="#{horizontal_svg_path(options)}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
|
90
|
+
<g>
|
91
|
+
<style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
|
92
|
+
#{horizontal_svg_text(options)}
|
93
|
+
</g>
|
94
|
+
SVG
|
95
|
+
end
|
96
|
+
|
97
|
+
def horizontal_svg_path(options)
|
98
|
+
<<~SVG
|
99
|
+
M#{options[:left]} #{options[:y]} l #{@arrow_size} #{@arrow_size} M#{options[:left]} #{options[:y]} l #{@arrow_size} -#{@arrow_size} M#{options[:left]} #{options[:y]} l #{options[:right] - options[:left]} 0 l -#{@arrow_size} -#{@arrow_size} M#{options[:right]} #{options[:y]} l -#{@arrow_size} #{@arrow_size}
|
100
|
+
SVG
|
101
|
+
end
|
102
|
+
|
103
|
+
def horizontal_svg_text(options)
|
104
|
+
<<~SVG
|
105
|
+
<text x="#{(options[:left] + options[:right]) / 2 + options[:label_offset_x]}" y="#{options[:y] + options[:label_offset]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
|
106
|
+
SVG
|
107
|
+
end
|
108
|
+
|
109
|
+
def load_common_config(fly)
|
110
|
+
@color = '#CCCCCC'
|
111
|
+
@stroke_width = (USPSFlags::Config::BASE_FLY / 600)
|
112
|
+
@stroke_dash = '10, 10'
|
113
|
+
@font_size = (USPSFlags::Config::BASE_FLY / 60)
|
114
|
+
@arrow_size = (USPSFlags::Config::BASE_FLY / 120)
|
115
|
+
@fly = fly || USPSFlags::Config::BASE_FLY
|
116
|
+
end
|
117
|
+
|
118
|
+
def arrow_pointer(options)
|
119
|
+
<<~SVG
|
120
|
+
<line x1="#{options[:x1]}" y1="#{options[:y1]}" x2="#{options[:x2]}" y2="#{options[:y2]}" stroke="#{@color}" stroke-width="#{@stroke_width}" stroke-dasharray="#{@stroke_dash}" />
|
121
|
+
SVG
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_labels(a, b)
|
125
|
+
label = (a - b) * Rational(@fly, USPSFlags::Config::BASE_FLY)
|
126
|
+
if label == label.to_i
|
127
|
+
label = label.to_i
|
128
|
+
label_fraction = ''
|
129
|
+
else
|
130
|
+
label, label_fraction = USPSFlags::Rational.new(label).to_simplified_a
|
131
|
+
end
|
132
|
+
[label, label_fraction]
|
133
|
+
end
|
129
134
|
end
|
130
|
-
[label, label_fraction]
|
131
135
|
end
|
132
136
|
end
|
133
137
|
end
|