usps_flags 0.3.26 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +87 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +2 -2
- data/Rakefile +4 -2
- data/lib/rational.rb +3 -1
- data/lib/usps_flags.rb +15 -17
- data/lib/usps_flags/config.rb +32 -29
- data/lib/usps_flags/core.rb +11 -9
- data/lib/usps_flags/core/ensign.rb +20 -17
- data/lib/usps_flags/core/field.rb +33 -30
- data/lib/usps_flags/core/footer.rb +2 -0
- data/lib/usps_flags/core/headers.rb +11 -8
- data/lib/usps_flags/core/icons.rb +14 -0
- data/lib/usps_flags/core/{anchor.rb → icons/anchor.rb} +7 -5
- data/lib/usps_flags/core/{binoculars.rb → icons/binoculars.rb} +7 -5
- data/lib/usps_flags/core/{lighthouse.rb → icons/lighthouse.rb} +3 -1
- data/lib/usps_flags/core/{star.rb → icons/star.rb} +3 -1
- data/lib/usps_flags/core/{trident.rb → icons/trident.rb} +29 -25
- data/lib/usps_flags/core/{trumpet.rb → icons/trumpet.rb} +3 -1
- data/lib/usps_flags/core/pennant.rb +20 -17
- data/lib/usps_flags/core/trident_spec.rb +62 -174
- data/lib/usps_flags/core/trident_specs.rb +14 -0
- data/lib/usps_flags/core/trident_specs/base.rb +15 -0
- data/lib/usps_flags/core/trident_specs/circle.rb +51 -0
- data/lib/usps_flags/core/trident_specs/delta.rb +68 -0
- data/lib/usps_flags/core/trident_specs/header.rb +65 -0
- data/lib/usps_flags/core/trident_specs/long.rb +54 -0
- data/lib/usps_flags/core/trident_specs/short.rb +176 -0
- data/lib/usps_flags/core/tridents.rb +16 -14
- data/lib/usps_flags/core/us.rb +9 -7
- data/lib/usps_flags/core/wheel.rb +2 -0
- data/lib/usps_flags/errors.rb +16 -4
- data/lib/usps_flags/generate.rb +48 -44
- data/lib/usps_flags/generate/flag.rb +33 -30
- data/lib/usps_flags/helpers.rb +48 -63
- data/lib/usps_flags/helpers/builders.rb +39 -37
- data/lib/usps_flags/helpers/spec_arrows.rb +16 -13
- data/spec/rational_spec.rb +9 -7
- data/spec/spec_helper.rb +5 -3
- data/spec/usps_flags/config_spec.rb +15 -13
- data/spec/usps_flags/core_spec.rb +52 -51
- data/spec/usps_flags/generate_spec.rb +70 -60
- data/spec/usps_flags/helpers_spec.rb +12 -10
- data/spec/usps_flags_spec.rb +22 -20
- data/usps_flags.gemspec +4 -2
- metadata +31 -21
data/lib/usps_flags/helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
# Container class for helper methods.
|
2
4
|
class USPSFlags::Helpers
|
3
5
|
class << self
|
@@ -30,11 +32,12 @@ class USPSFlags::Helpers
|
|
30
32
|
def resize_png(png_file, file: nil, outfile: nil, size:, size_key: nil)
|
31
33
|
raise USPSFlags::Errors::PNGConversionError if outfile.nil? && file.nil?
|
32
34
|
raise USPSFlags::Errors::PNGConversionError if outfile.nil? && size_key.nil?
|
35
|
+
|
33
36
|
output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
|
34
37
|
MiniMagick::Tool::Convert.new do |convert|
|
35
|
-
convert <<
|
36
|
-
convert <<
|
37
|
-
convert <<
|
38
|
+
convert << '-background' << 'none'
|
39
|
+
convert << '-format' << 'png'
|
40
|
+
convert << '-resize' << "#{size}"
|
38
41
|
convert << png_file
|
39
42
|
convert << output_file_name
|
40
43
|
end
|
@@ -67,7 +70,7 @@ class USPSFlags::Helpers
|
|
67
70
|
# This is used USPSFlags::Generate, and should never need to be called directly.
|
68
71
|
# @private
|
69
72
|
def png_sizes
|
70
|
-
{1500 =>
|
73
|
+
{ 1500 => 'H', 1000 => 'K', 500 => 'D', 'thumb' => 'T' }
|
71
74
|
end
|
72
75
|
|
73
76
|
# Gets size key for saving PNG images.
|
@@ -75,18 +78,18 @@ class USPSFlags::Helpers
|
|
75
78
|
# This is used USPSFlags::Generate, and should never need to be called directly.
|
76
79
|
# @private
|
77
80
|
def size_and_key(size:, flag:)
|
78
|
-
return [size, size] unless size ==
|
81
|
+
return [size, size] unless size == 'thumb'
|
79
82
|
|
80
83
|
size = case flag
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
when 'ENSIGN'
|
85
|
+
200
|
86
|
+
when 'US'
|
87
|
+
300
|
88
|
+
else
|
89
|
+
150
|
87
90
|
end
|
88
91
|
|
89
|
-
[size,
|
92
|
+
[size, 'thumb']
|
90
93
|
end
|
91
94
|
|
92
95
|
# Prints message(s) to the console and logs them.
|
@@ -114,11 +117,11 @@ class USPSFlags::Helpers
|
|
114
117
|
# This should never need to be called directly.
|
115
118
|
# @private
|
116
119
|
def ensure_dir_for_file(path)
|
117
|
-
return false if path.nil? || path.empty? || !path.scan(
|
120
|
+
return false if path.nil? || path.empty? || !path.scan('/')
|
118
121
|
|
119
|
-
dirs = path.split(
|
122
|
+
dirs = path.split('/')
|
120
123
|
dirs.pop
|
121
|
-
::FileUtils.mkdir_p(dirs.join(
|
124
|
+
::FileUtils.mkdir_p(dirs.join('/')).first
|
122
125
|
end
|
123
126
|
|
124
127
|
# Prints output to the console or saves to a file, then returns the generated data.
|
@@ -128,16 +131,17 @@ class USPSFlags::Helpers
|
|
128
131
|
def output(svg, outfile: nil)
|
129
132
|
if outfile.nil?
|
130
133
|
puts svg, "\n"
|
131
|
-
elsif outfile !=
|
134
|
+
elsif outfile != ''
|
132
135
|
ensure_dir_for_file(outfile)
|
133
|
-
f = ::File.new(outfile,
|
136
|
+
f = ::File.new(outfile, 'w+')
|
134
137
|
f.write(svg)
|
135
138
|
f.close
|
136
139
|
end
|
137
140
|
svg
|
138
141
|
end
|
139
142
|
|
140
|
-
|
143
|
+
private
|
144
|
+
|
141
145
|
def load_valid_flags
|
142
146
|
@squadron_past = %w[PLTC PC]
|
143
147
|
@squadron_elected = %w[1LT LTC CDR]
|
@@ -148,7 +152,7 @@ class USPSFlags::Helpers
|
|
148
152
|
@national_past = %w[PSTFC PRC PVC PCC]
|
149
153
|
@national_elected = %w[STFC RC VC CC]
|
150
154
|
@national_swallowtail = %w[NAIDE NFLT]
|
151
|
-
@special = %w[CRUISE OIC ENSIGN WHEEL
|
155
|
+
@special = %w[CRUISE OIC ENSIGN] # WHEEL
|
152
156
|
@us = %w[US]
|
153
157
|
|
154
158
|
@past = @squadron_past + @district_past + @national_past
|
@@ -173,65 +177,50 @@ class USPSFlags::Helpers
|
|
173
177
|
insignia: @officer - @past,
|
174
178
|
swallowtail: @past + @squadron_swallowtail + @district_swallowtail + @national_swallowtail,
|
175
179
|
|
176
|
-
bridge: @squadron_elected.last(2) + @squadron_past.last(2) +
|
177
|
-
@district_elected.last(2) + @district_past.last(2) +
|
180
|
+
bridge: @squadron_elected.last(2) + @squadron_past.last(2) +
|
181
|
+
@district_elected.last(2) + @district_past.last(2) +
|
178
182
|
@national_elected.last(2) + @national_past.last(2),
|
179
183
|
|
180
184
|
command: [@squadron_elected.last, @squadron_past.last,
|
181
|
-
|
182
|
-
|
185
|
+
@district_elected.last, @district_past.last,
|
186
|
+
@national_elected.last, @national_past.last]
|
183
187
|
}[type]
|
184
188
|
end
|
185
189
|
|
186
190
|
def flag_style(rank)
|
187
|
-
if valid_flags(:past).include?(rank)
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
else
|
192
|
-
:regular
|
193
|
-
end
|
191
|
+
return :past if valid_flags(:past).include?(rank)
|
192
|
+
return :swallowtail if valid_flags(:swallowtail).include?(rank)
|
193
|
+
|
194
|
+
:regular
|
194
195
|
end
|
195
196
|
|
196
197
|
def flag_color(rank)
|
197
|
-
if valid_flags(:command).include?(rank)
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
count = 2
|
202
|
-
:red
|
203
|
-
else
|
204
|
-
:white
|
205
|
-
end
|
198
|
+
return :blue if valid_flags(:command).include?(rank)
|
199
|
+
return :red if valid_flags(:bridge).include?(rank)
|
200
|
+
|
201
|
+
:white
|
206
202
|
end
|
207
203
|
|
208
204
|
def flag_level(rank)
|
209
|
-
if rank.match /N.*/
|
210
|
-
|
211
|
-
|
212
|
-
:d
|
213
|
-
elsif rank == "FLT"
|
214
|
-
:s
|
215
|
-
end
|
205
|
+
return :n if rank.match? /N.*/
|
206
|
+
return :d if rank.match? /D.*/
|
207
|
+
return :s if rank == 'FLT'
|
216
208
|
end
|
217
209
|
|
218
210
|
def flag_count(rank)
|
219
|
-
if valid_flags(:command).include?(rank)
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
else
|
224
|
-
1
|
225
|
-
end
|
211
|
+
return 3 if valid_flags(:command).include?(rank)
|
212
|
+
return 2 if valid_flags(:bridge).include?(rank)
|
213
|
+
|
214
|
+
1
|
226
215
|
end
|
227
216
|
|
228
217
|
def flag_type(rank) # Complexity
|
229
|
-
specifics = {
|
218
|
+
specifics = { 'PORTCAP' => :pc, 'FLEETCAP' => :fc, 'STFC' => :stf }
|
230
219
|
if specifics.keys.include?(rank)
|
231
220
|
specifics[rank]
|
232
|
-
elsif rank.match /.AIDE/
|
221
|
+
elsif rank.match? /.AIDE/
|
233
222
|
:a
|
234
|
-
elsif rank.match /.?FLT/
|
223
|
+
elsif rank.match? /.?FLT/
|
235
224
|
:f
|
236
225
|
else
|
237
226
|
get_line_flag_level(rank)
|
@@ -239,13 +228,9 @@ class USPSFlags::Helpers
|
|
239
228
|
end
|
240
229
|
|
241
230
|
def get_line_flag_level(rank)
|
242
|
-
if valid_flags(:squadron).include?(rank)
|
243
|
-
|
244
|
-
|
245
|
-
:d
|
246
|
-
elsif valid_flags(:national).include?(rank)
|
247
|
-
:n
|
248
|
-
end
|
231
|
+
return :s if valid_flags(:squadron).include?(rank)
|
232
|
+
return :d if valid_flags(:district).include?(rank)
|
233
|
+
return :n if valid_flags(:national).include?(rank)
|
249
234
|
end
|
250
235
|
end
|
251
236
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
# SVG building helpers.
|
2
4
|
#
|
3
5
|
# These methods should never need to be called directly, except when designing new flags.
|
@@ -10,38 +12,38 @@ class USPSFlags::Helpers::Builders
|
|
10
12
|
# @private
|
11
13
|
def grid(width: USPSFlags::Config::BASE_FLY, height: USPSFlags::Config::BASE_HOIST)
|
12
14
|
<<~SVG
|
13
|
-
<circle cx="0" cy="0" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
14
|
-
<circle cx="#{width}" cy="0" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
15
|
-
<circle cx="#{width}" cy="#{height}" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
16
|
-
<circle cx="0" cy="#{height}" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
15
|
+
<circle cx="0" cy="0" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
|
16
|
+
<circle cx="#{width}" cy="0" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
|
17
|
+
<circle cx="#{width}" cy="#{height}" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
|
18
|
+
<circle cx="0" cy="#{height}" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
|
17
19
|
|
18
|
-
<circle cx="#{width*1/4}" cy="#{height/2}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
19
|
-
<circle cx="#{width*3/4}" cy="#{height/2}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
20
|
+
<circle cx="#{width * 1 / 4}" cy="#{height / 2}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
|
21
|
+
<circle cx="#{width * 3 / 4}" cy="#{height / 2}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
|
20
22
|
|
21
|
-
<circle cx="#{width/2}" cy="#{height*1/4}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
22
|
-
<circle cx="#{width/2}" cy="#{height/2}" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
23
|
-
<circle cx="#{width/2}" cy="#{height/2}" r="#{width/75}" fill="#CCCCCC" fill-opacity="0.4" />
|
24
|
-
<circle cx="#{width/2}" cy="#{height/2}" r="#{width/100}" fill="#000000" fill-opacity="0.4" />
|
25
|
-
<circle cx="#{width/2}" cy="#{height*3/4}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
23
|
+
<circle cx="#{width / 2}" cy="#{height * 1 / 4}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
|
24
|
+
<circle cx="#{width / 2}" cy="#{height / 2}" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
|
25
|
+
<circle cx="#{width / 2}" cy="#{height / 2}" r="#{width / 75}" fill="#CCCCCC" fill-opacity="0.4" />
|
26
|
+
<circle cx="#{width / 2}" cy="#{height / 2}" r="#{width / 100}" fill="#000000" fill-opacity="0.4" />
|
27
|
+
<circle cx="#{width / 2}" cy="#{height * 3 / 4}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
|
26
28
|
|
27
|
-
<line x1="0" y1="0" x2="#{width}" y2="0" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
28
|
-
<line x1="0" y1="#{height*1/4}" x2="#{width}" y2="#{height*1/4}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
29
|
-
<line x1="0" y1="#{height/2}" x2="#{width}" y2="#{height/2}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
30
|
-
<line x1="0" y1="#{height*3/4}" x2="#{width}" y2="#{height*3/4}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
31
|
-
<line x1="0" y1="#{height}" x2="#{width}" y2="#{height}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
29
|
+
<line x1="0" y1="0" x2="#{width}" y2="0" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
30
|
+
<line x1="0" y1="#{height * 1 / 4}" x2="#{width}" y2="#{height * 1 / 4}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
31
|
+
<line x1="0" y1="#{height / 2}" x2="#{width}" y2="#{height / 2}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
32
|
+
<line x1="0" y1="#{height * 3 / 4}" x2="#{width}" y2="#{height * 3 / 4}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
33
|
+
<line x1="0" y1="#{height}" x2="#{width}" y2="#{height}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
32
34
|
|
33
|
-
<line y1="0" x1="0" y2="#{height}" x2="0" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
34
|
-
<line y1="0" x1="#{width*1/6}" y2="#{height}" x2="#{width*1/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
35
|
-
<line y1="0" x1="#{width*2/6}" y2="#{height}" x2="#{width*2/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
36
|
-
<line y1="0" x1="#{width*3/6}" y2="#{height}" x2="#{width*3/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
37
|
-
<line y1="0" x1="#{width*4/6}" y2="#{height}" x2="#{width*4/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
38
|
-
<line y1="0" x1="#{width*5/6}" y2="#{height}" x2="#{width*5/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
39
|
-
<line y1="0" x1="#{width}" y2="#{height}" x2="#{width}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
35
|
+
<line y1="0" x1="0" y2="#{height}" x2="0" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
36
|
+
<line y1="0" x1="#{width * 1 / 6}" y2="#{height}" x2="#{width * 1 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
37
|
+
<line y1="0" x1="#{width * 2 / 6}" y2="#{height}" x2="#{width * 2 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
38
|
+
<line y1="0" x1="#{width * 3 / 6}" y2="#{height}" x2="#{width * 3 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
39
|
+
<line y1="0" x1="#{width * 4 / 6}" y2="#{height}" x2="#{width * 4 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
40
|
+
<line y1="0" x1="#{width * 5 / 6}" y2="#{height}" x2="#{width * 5 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
41
|
+
<line y1="0" x1="#{width}" y2="#{height}" x2="#{width}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
40
42
|
|
41
|
-
<line x1="#{width/2}" y1="#{height*1/4}" x2="#{width*3/4}" y2="#{height/2}" stroke="#999999" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
42
|
-
<line x1="#{width*3/4}" y1="#{height/2}" x2="#{width/2}" y2="#{height*3/4}" stroke="#999999" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
43
|
-
<line x1="#{width/2}" y1="#{height*3/4}" x2="#{width*1/4}" y2="#{height/2}" stroke="#999999" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
44
|
-
<line x1="#{width*1/4}" y1="#{height/2}" x2="#{width/2}" y2="#{height*1/4}" stroke="#999999" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
43
|
+
<line x1="#{width / 2}" y1="#{height * 1 / 4}" x2="#{width * 3 / 4}" y2="#{height / 2}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
44
|
+
<line x1="#{width * 3 / 4}" y1="#{height / 2}" x2="#{width / 2}" y2="#{height * 3 / 4}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
45
|
+
<line x1="#{width / 2}" y1="#{height * 3 / 4}" x2="#{width * 1 / 4}" y2="#{height / 2}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
46
|
+
<line x1="#{width * 1 / 4}" y1="#{height / 2}" x2="#{width / 2}" y2="#{height * 1 / 4}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
|
45
47
|
|
46
48
|
SVG
|
47
49
|
end
|
@@ -52,19 +54,19 @@ class USPSFlags::Helpers::Builders
|
|
52
54
|
# @private
|
53
55
|
def locator
|
54
56
|
<<~SVG
|
55
|
-
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY*2}" fill="#000000" fill-opacity="0.4" />
|
57
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY * 2}" fill="#000000" fill-opacity="0.4" />
|
56
58
|
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY}" fill="#333333" fill-opacity="0.4" />
|
57
|
-
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/2}" fill="#666666" fill-opacity="0.4" />
|
58
|
-
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/4}" fill="#999999" fill-opacity="0.4" />
|
59
|
-
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/8}" fill="#CCCCCC" fill-opacity="0.4" />
|
60
|
-
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/16}" fill="#FFFFFF" fill-opacity="0.4" />
|
59
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 2}" fill="#666666" fill-opacity="0.4" />
|
60
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 4}" fill="#999999" fill-opacity="0.4" />
|
61
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 8}" fill="#CCCCCC" fill-opacity="0.4" />
|
62
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY / 16}" fill="#FFFFFF" fill-opacity="0.4" />
|
61
63
|
|
62
|
-
<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}" />
|
63
|
-
<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}" />
|
64
|
-
<line x1="0" y1="#{USPSFlags::Config::BASE_HOIST}" x2="0" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
65
|
-
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="0" x2="#{USPSFlags::Config::BASE_FLY}" y2="0" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
64
|
+
<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}" />
|
65
|
+
<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}" />
|
66
|
+
<line x1="0" y1="#{USPSFlags::Config::BASE_HOIST}" x2="0" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
67
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="0" x2="#{USPSFlags::Config::BASE_FLY}" y2="0" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
66
68
|
|
67
|
-
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY/30}" height="#{USPSFlags::Config::BASE_FLY/30}" fill="#333333" fill-opacity="0.6" />
|
69
|
+
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY / 30}" height="#{USPSFlags::Config::BASE_FLY / 30}" fill="#333333" fill-opacity="0.6" />
|
68
70
|
SVG
|
69
71
|
end
|
70
72
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
# Trident specification sheet arrows.
|
2
4
|
#
|
3
5
|
# These methods should never need to be called directly.
|
@@ -8,10 +10,10 @@ class USPSFlags::Helpers::SpecArrows
|
|
8
10
|
#
|
9
11
|
# This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
|
10
12
|
# @private
|
11
|
-
def vertical(x, top, bottom, pointer_top = nil, pointer_bottom = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY/120), label_offset_y: 0, label_align:
|
13
|
+
def vertical(x, top, bottom, pointer_top = nil, pointer_bottom = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / 120), label_offset_y: 0, label_align: 'left')
|
12
14
|
load_common_config(fly)
|
13
15
|
label, label_fraction = get_labels(bottom, top)
|
14
|
-
svg =
|
16
|
+
svg = ''
|
15
17
|
|
16
18
|
svg << arrow_pointer(x, pointer_top, top, top) unless pointer_top.nil?
|
17
19
|
svg << arrow_pointer(x, pointer_bottom, bottom, bottom) unless pointer_bottom.nil?
|
@@ -20,7 +22,7 @@ class USPSFlags::Helpers::SpecArrows
|
|
20
22
|
<path d="M#{x} #{top} l #{@arrow_size} #{@arrow_size} M#{x} #{top} l -#{@arrow_size} #{@arrow_size} M#{x} #{top} l 0 #{bottom - top} l #{@arrow_size} -#{@arrow_size} M#{x} #{bottom} l -#{@arrow_size} -#{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
|
21
23
|
<g>
|
22
24
|
<style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
|
23
|
-
<text x="#{x + label_offset}" y="#{(top+bottom)/2+(USPSFlags::Config::BASE_HOIST/150)+label_offset_y}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{label_align}">#{label} <tspan>#{label_fraction}</tspan> #{unit}</text>
|
25
|
+
<text x="#{x + label_offset}" y="#{(top + bottom) / 2 + (USPSFlags::Config::BASE_HOIST / 150) + label_offset_y}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{label_align}">#{label} <tspan>#{label_fraction}</tspan> #{unit}</text>
|
24
26
|
</g>
|
25
27
|
SVG
|
26
28
|
|
@@ -31,10 +33,10 @@ class USPSFlags::Helpers::SpecArrows
|
|
31
33
|
#
|
32
34
|
# This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
|
33
35
|
# @private
|
34
|
-
def horizontal(y, left, right, pointer_left = nil, pointer_right = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY/45), label_offset_x: 0, label_align:
|
36
|
+
def horizontal(y, left, right, pointer_left = nil, pointer_right = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / 45), label_offset_x: 0, label_align: 'middle')
|
35
37
|
load_common_config(fly)
|
36
38
|
label, label_fraction = get_labels(right, left)
|
37
|
-
svg =
|
39
|
+
svg = ''
|
38
40
|
|
39
41
|
svg << arrow_pointer(left, left, pointer_left, y) unless pointer_left.nil?
|
40
42
|
svg << arrow_pointer(right, right, y, pointer_right) unless pointer_right.nil?
|
@@ -43,20 +45,21 @@ class USPSFlags::Helpers::SpecArrows
|
|
43
45
|
<path d="M#{left} #{y} l #{@arrow_size} #{@arrow_size} M#{left} #{y} l #{@arrow_size} -#{@arrow_size} M#{left} #{y} l #{right - left} 0 l -#{@arrow_size} -#{@arrow_size} M#{right} #{y} l -#{@arrow_size} #{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
|
44
46
|
<g>
|
45
47
|
<style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
|
46
|
-
<text x="#{(left+right)/2+label_offset_x}" y="#{y + label_offset}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{label_align}">#{label} <tspan>#{label_fraction}</tspan> #{unit}</text>
|
48
|
+
<text x="#{(left + right) / 2 + label_offset_x}" y="#{y + label_offset}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{label_align}">#{label} <tspan>#{label_fraction}</tspan> #{unit}</text>
|
47
49
|
</g>
|
48
50
|
SVG
|
49
51
|
|
50
52
|
svg
|
51
53
|
end
|
52
54
|
|
53
|
-
|
55
|
+
private
|
56
|
+
|
54
57
|
def load_common_config(fly)
|
55
|
-
@color =
|
56
|
-
@stroke_width = (USPSFlags::Config::BASE_FLY/600)
|
57
|
-
@stroke_dash =
|
58
|
-
@font_size = (USPSFlags::Config::BASE_FLY/60)
|
59
|
-
@arrow_size = (USPSFlags::Config::BASE_FLY/120)
|
58
|
+
@color = '#CCCCCC'
|
59
|
+
@stroke_width = (USPSFlags::Config::BASE_FLY / 600)
|
60
|
+
@stroke_dash = '10, 10'
|
61
|
+
@font_size = (USPSFlags::Config::BASE_FLY / 60)
|
62
|
+
@arrow_size = (USPSFlags::Config::BASE_FLY / 120)
|
60
63
|
@fly = fly || USPSFlags::Config::BASE_FLY
|
61
64
|
end
|
62
65
|
|
@@ -70,7 +73,7 @@ class USPSFlags::Helpers::SpecArrows
|
|
70
73
|
label = (a - b) * Rational(@fly, USPSFlags::Config::BASE_FLY)
|
71
74
|
if label == label.to_i
|
72
75
|
label = label.to_i
|
73
|
-
label_fraction =
|
76
|
+
label_fraction = ''
|
74
77
|
else
|
75
78
|
label, label_fraction = label.to_simplified_a
|
76
79
|
end
|
data/spec/rational_spec.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Rational do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
expect(Rational(4,3).to_simplified_a).to eql([1, Rational(1,3)])
|
6
|
+
describe 'monkey patches' do
|
7
|
+
it 'should render a simplified fraction as an Array' do
|
8
|
+
expect(Rational(4, 3).to_simplified_a).to eql([1, Rational(1, 3)])
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
10
|
-
expect(Rational(2,3).to_simplified_a).to eql(
|
11
|
+
it 'should render a proper fraction as String' do
|
12
|
+
expect(Rational(2, 3).to_simplified_a).to eql('2/3')
|
11
13
|
end
|
12
14
|
|
13
|
-
it
|
14
|
-
expect(Rational(4,3).to_simplified_s).to eql(
|
15
|
+
it 'should render a simplified fraction as a String' do
|
16
|
+
expect(Rational(4, 3).to_simplified_s).to eql('1 1/3')
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
require 'bundler/setup'
|
2
4
|
Bundler.setup
|
3
5
|
require 'simplecov'
|
@@ -10,8 +12,8 @@ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
|
|
10
12
|
|
11
13
|
RSpec.configure do |config|
|
12
14
|
config.before(:suite) do
|
13
|
-
$tmp_flags_dir =
|
14
|
-
$tmp_alt_flags_dir =
|
15
|
+
$tmp_flags_dir = 'tmp/flags'
|
16
|
+
$tmp_alt_flags_dir = 'tmp/alt_flags'
|
15
17
|
|
16
18
|
USPSFlags.configure do |c|
|
17
19
|
c.flags_dir = $tmp_flags_dir
|
@@ -20,6 +22,6 @@ RSpec.configure do |config|
|
|
20
22
|
end
|
21
23
|
|
22
24
|
config.after(:suite) do
|
23
|
-
::FileUtils.rm_rf(
|
25
|
+
::FileUtils.rm_rf('tmp') if ::Dir.exist?('tmp')
|
24
26
|
end
|
25
27
|
end
|
@@ -1,29 +1,31 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe USPSFlags::Config do
|
4
|
-
describe
|
5
|
-
it
|
6
|
+
describe 'class variable accessors' do
|
7
|
+
it 'should return the current flags directory' do
|
6
8
|
expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
10
|
-
default_log_path = $tmp_flags_dir +
|
11
|
+
it 'should return the current flags directory' do
|
12
|
+
default_log_path = $tmp_flags_dir + '/log'
|
11
13
|
expect(USPSFlags.configuration.log_path).to eql(default_log_path)
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
16
|
+
it 'should return a Boolean from clear' do
|
15
17
|
expect([true, false]).to include(USPSFlags.configuration.clear)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
describe
|
20
|
-
it
|
21
|
+
describe 'trident' do
|
22
|
+
it 'should return a Hash from trident' do
|
21
23
|
expect(USPSFlags.configuration.trident).to be_a(Hash)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
describe
|
26
|
-
it
|
27
|
+
describe 'configuration constructor' do
|
28
|
+
it 'should return a properly constructed configuration' do
|
27
29
|
USPSFlags.configure do |config|
|
28
30
|
config.flags_dir = $tmp_flags_dir
|
29
31
|
end
|
@@ -33,11 +35,11 @@ describe USPSFlags::Config do
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
describe
|
38
|
+
describe 'Rails configuration' do
|
37
39
|
before(:each) do
|
38
40
|
class Rails
|
39
41
|
def self.root
|
40
|
-
|
42
|
+
'tmp/rails_app'
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -46,8 +48,8 @@ describe USPSFlags::Config do
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
it
|
50
|
-
expect(@config.log_path).to eql(
|
51
|
+
it 'should use the default Rails log directory' do
|
52
|
+
expect(@config.log_path).to eql('tmp/rails_app/log')
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|