usps_flags 0.1.24 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d7be3f498ef55ebeea23f8c4f4e3572143a8a91
4
- data.tar.gz: d0a965e161b9d00615b97eeb57b070fcfcab03d3
3
+ metadata.gz: 143f1a8c230ced0a6083dc05b6f37f95e8069d7a
4
+ data.tar.gz: 6edb326954eb641bb49db42d949983f93f528d3e
5
5
  SHA512:
6
- metadata.gz: b63188da58d8a31335b3f39270555f6932da81c57eb1ea4379e21f09f20e518be0aef44aa0d9c25fb65494224b1592554e95806e70f6e59eeb9e7d985bced9fb
7
- data.tar.gz: 98197bffb245b5d4662cd203e53228268c5e41a16000da1a1319fdc83d3c36376be0b58acb9b1f67e335cdbe2c0c12b9d6c687bd2bdf4635d6b89e904bd8f62b
6
+ metadata.gz: 2ac2761bf82c24039358ae4b5eadb66cb7f92f8b5e5624594018ca7916fc969f990d0eed04474e987ea00b24a4e73d739d6ee33ba9a9a38751c4088996da7c1d
7
+ data.tar.gz: fb7c5156a9a3c07c0e14d87d4776c670099bd16d896eec6d1cf21907da200106de8688238e66dcea3b44b5414573625dbed923b40e541d8efa92170c440bfeba
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.1.24)
4
+ usps_flags (0.1.25)
5
5
  file_utils (~> 1.1, >= 1.1.2)
6
6
  mini_magick (~> 4.8, >= 4.8.0)
7
7
  rubyzip (~> 1.2, >= 1.2.1)
@@ -52,19 +52,9 @@ class USPSFlags::Generate
52
52
  # @param [Boolean] zips Whether to create zip archives for all images created. Does not create a zip for skipped formats.
53
53
  # @param [Boolean] reset Whether to delete all previous files before generating new files.
54
54
  def self.all(svg: true, png: true, zips: true, reset: true)
55
- if reset
56
- ::FileUtils.rm_rf(Dir.glob("#{USPSFlags::Config.flags_dir}/SVG/*"))
57
- ::FileUtils.rm_rf(Dir.glob("#{USPSFlags::Config.flags_dir}/PNG/*"))
58
- ::FileUtils.rm_rf(Dir.glob("#{USPSFlags::Config.flags_dir}/ZIP/*"))
59
- ::FileUtils.mkdir_p("#{USPSFlags::Config.flags_dir}/SVG/insignia")
60
- ::FileUtils.mkdir_p("#{USPSFlags::Config.flags_dir}/PNG/insignia")
61
- puts "Cleared previous files."
62
- end
63
-
64
- flags = USPSFlags::Helpers.valid_flags(:all)
65
- insignia_flags = USPSFlags::Helpers.valid_flags(:insignia)
55
+ self.remove_static_files if reset
66
56
 
67
- max_length = flags.map(&:length).max
57
+ max_length = USPSFlags::Helpers.valid_flags(:all).map(&:length).max
68
58
  puts "\nSVGs generate a single file.",
69
59
  "PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.",
70
60
  "Corresponding rank insignia (including smaller sizes) are also generated, as appropriate."
@@ -74,108 +64,8 @@ class USPSFlags::Generate
74
64
 
75
65
  overall_start_time = Time.now
76
66
 
77
- flags.each do |flag|
78
- start_time = Time.now
79
- USPSFlags::Helpers.log " | | _ _ _ _ _ | \r".rjust(max_length+31, " ")
80
- flag = flag.upcase
81
- USPSFlags::Helpers.log "#{flag.rjust(max_length)} |"
82
-
83
- svg_file = "#{USPSFlags::Config.flags_dir}/SVG/#{flag}.svg"
84
- png_file = "#{USPSFlags::Config.flags_dir}/PNG/#{flag}.png"
85
-
86
- svg_ins_file = "#{USPSFlags::Config.flags_dir}/SVG/insignia/#{flag}.svg"
87
- png_ins_file = "#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.png"
88
-
89
- past = (flag[0] == "P" && flag != "PORTCAP")
90
-
91
- if svg
92
- begin
93
- USPSFlags::Helpers.log " "
94
- self.get flag, outfile: svg_file, scale: 1
95
- USPSFlags::Helpers.log "S"
96
- if past || !insignia_flags.include?(flag)
97
- USPSFlags::Helpers.log "-"
98
- else
99
- self.get flag, field: false, outfile: svg_ins_file, scale: 1
100
- USPSFlags::Helpers.log "I"
101
- end
102
- rescue => e
103
- USPSFlags::Helpers.log "x -> #{e.message}"
104
- end
105
- else
106
- USPSFlags::Helpers.log "-"
107
- end
108
-
109
- if png
110
- USPSFlags::Helpers.log " | "
111
- begin
112
- USPSFlags::Helpers.log "…\b"
113
- USPSFlags::Generate.png(File.read(svg_file), outfile: png_file) unless ::File.exists?(png_file)
114
- USPSFlags::Helpers.log "F"
115
- if past || !insignia_flags.include?(flag)
116
- USPSFlags::Helpers.log "-"
117
- else
118
- USPSFlags::Helpers.log "…\b"
119
- USPSFlags::Generate.png(File.read(svg_ins_file), outfile: png_ins_file, trim: true) unless ::File.exists?(png_ins_file)
120
- USPSFlags::Helpers.log "I"
121
- end
122
- sizes = {1500 => "H", 1000 => "K", 500 => "D", "thumb" => "T"}
123
- sizes.keys.each do |size|
124
- if ::File.exists?("#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size}.png")
125
- USPSFlags::Helpers.log "."
126
- else
127
- USPSFlags::Helpers.log "…\b"
128
- if size == "thumb"
129
- size_key = size
130
- size = case flag
131
- when "ENSIGN"
132
- 200
133
- when "US"
134
- 300
135
- else
136
- 150
137
- end
138
- else
139
- size_key = size
140
- end
141
- MiniMagick::Tool::Convert.new do |convert|
142
- convert << "-background" << "none"
143
- convert << "-format" << "png"
144
- convert << "-resize" << "#{size}"
145
- convert << png_file
146
- convert << "#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size_key}.png"
147
- end
148
- USPSFlags::Helpers.log sizes[size_key]
149
-
150
- if ::File.exists?(png_ins_file)
151
- if ::File.exists?("#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size}.png")
152
- USPSFlags::Helpers.log "."
153
- elsif MiniMagick::Image.open(png_ins_file)[:width] > size
154
- USPSFlags::Helpers.log "…\b"
155
- MiniMagick::Tool::Convert.new do |convert|
156
- convert << "-background" << "none"
157
- convert << "-format" << "png"
158
- convert << "-resize" << "#{size}"
159
- convert << png_ins_file
160
- convert << "#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size_key}.png"
161
- end
162
- USPSFlags::Helpers.log "i"
163
- else
164
- USPSFlags::Helpers.log "+"
165
- end
166
- else
167
- USPSFlags::Helpers.log "-"
168
- end
169
- end
170
- end
171
- rescue => e
172
- USPSFlags::Helpers.log "x -> #{e.message}"
173
- end
174
- else
175
- USPSFlags::Helpers.log "- "
176
- end
177
- run_time = (Time.now - start_time).round(4).to_s[(0..5)].ljust(6, "0")
178
- USPSFlags::Helpers.log " | #{run_time} s\n"
67
+ USPSFlags::Helpers.valid_flags(:all).each do |flag|
68
+ self.generate_static_images_for(flag, svg: svg, png: png)
179
69
  end
180
70
 
181
71
  self.zips(svg: svg, png: png) if zips
@@ -241,151 +131,66 @@ class USPSFlags::Generate
241
131
  def self.flag(rank: nil, width: USPSFlags::Config::BASE_FLY, outfile: nil, scale: nil, field: true)
242
132
  raise "Error: No rank specified." if rank.nil?
243
133
  final_svg = ""
244
-
245
134
  final_svg << USPSFlags::Core.headers(scale: scale, title: rank)
246
135
 
247
- rank.slice!(0) if !field && rank[0].upcase == "P" && rank != "PORTCAP"
136
+ rank = rank.to_s.upcase
137
+ rank.slice!(0) if !field && USPSFlags::Helpers.valid_flags(:past).include?(rank)
248
138
  rank = "CDR" if rank == "C"
249
139
 
250
- case rank.upcase
251
- when "PLTC"
252
- style = :past
253
- color = :red
254
- type = :s
255
- count = 2
256
- when "PC"
257
- style = :past
258
- color = :blue
259
- type = :s
260
- count = 3
261
- when "PORTCAP"
262
- style = :swallowtail
263
- color = :white
264
- type = :pc
265
- count = 1
266
- when "FLEETCAP"
267
- style = :swallowtail
268
- color = :white
269
- type = :fc
270
- count = 1
271
- when "LT"
272
- style = :swallowtail
273
- color = :white
274
- type = :s
275
- count = 1
276
- when "FLT"
277
- style = :swallowtail
278
- color = :white
279
- type = :f
280
- count = 1
281
- when "1LT"
282
- style = :regular
283
- color = :white
284
- type = :s
285
- count = 1
286
- when "LTC"
287
- style = :regular
288
- color = :red
289
- type = :s
290
- count = 2
291
- when "CDR"
292
- style = :regular
293
- color = :blue
294
- type = :s
295
- count = 3
140
+ style = if USPSFlags::Helpers.valid_flags(:past).include?(rank)
141
+ :past
142
+ elsif USPSFlags::Helpers.valid_flags(:swallowtail).include?(rank)
143
+ :swallowtail
144
+ else
145
+ :regular
146
+ end
296
147
 
297
- when "PDLTC"
298
- style = :past
299
- color = :red
300
- type = :d
301
- count = 2
302
- when "PDC"
303
- style = :past
304
- color = :blue
305
- type = :d
148
+ color = if USPSFlags::Helpers.valid_flags(:command).include?(rank)
306
149
  count = 3
307
- when "DLT"
308
- style = :swallowtail
309
- color = :white
310
- type = :d
311
- count = 1
312
- when "DAIDE"
313
- style = :swallowtail
314
- color = :white
315
- type = :a
316
- count = 1
317
- when "DFLT"
318
- style = :swallowtail
319
- color = :white
320
- type = :f
321
- count = 2
322
- when "D1LT"
323
- style = :regular
324
- color = :white
325
- type = :d
326
- count = 1
327
- when "DLTC"
328
- style = :regular
329
- color = :red
330
- type = :d
150
+ :blue
151
+ elsif USPSFlags::Helpers.valid_flags(:bridge).include?(rank)
331
152
  count = 2
332
- when "DC"
333
- style = :regular
334
- color = :blue
335
- type = :d
336
- count = 3
153
+ :red
154
+ else
155
+ :white
156
+ end
337
157
 
338
- when "PSTFC"
339
- style = :past
340
- color = :white
341
- type = :stf
158
+ trident_color = field ? :white : color
159
+
160
+ type = if USPSFlags::Helpers.valid_flags(:squadron).include?(rank)
161
+ :s
162
+ elsif USPSFlags::Helpers.valid_flags(:district).include?(rank)
163
+ :d
164
+ elsif rank == "STFC"
165
+ :stf
166
+ elsif USPSFlags::Helpers.valid_flags(:national).include?(rank)
167
+ :n
168
+ elsif rank == "PORTCAP"
169
+ :pc
170
+ elsif rank == "FLEETCAP"
171
+ :fc
172
+ elsif rank == "DAIDE"
342
173
  count = 1
343
- when "PRC"
344
- style = :past
345
- color = :white
346
- type = :n
347
- count = 1
348
- when "PVC"
349
- style = :past
350
- color = :red
351
- type = :n
352
- count = 2
353
- when "PCC"
354
- style = :past
355
- color = :blue
356
- type = :n
357
- count = 3
358
- when "NAIDE"
359
- style = :swallowtail
360
- color = :white
361
- type = :a
174
+ level = :d
175
+ :a
176
+ elsif rank == "NAIDE"
362
177
  count = 2
363
- when "NFLT"
364
- style = :swallowtail
365
- color = :white
366
- type = :f
367
- count = 3
368
- when "STFC"
369
- style = :regular
370
- color = :white
371
- type = :stf
178
+ level = :n
179
+ :a
180
+ elsif rank == "FLT"
372
181
  count = 1
373
- when "RC"
374
- style = :regular
375
- color = :white
376
- type = :n
377
- count = 1
378
- when "VC"
379
- style = :regular
380
- color = :red
381
- type = :n
182
+ level = :s
183
+ :f
184
+ elsif rank == "DFLT"
382
185
  count = 2
383
- when "CC"
384
- style = :regular
385
- color = :blue
386
- type = :n
186
+ level = :d
187
+ :f
188
+ elsif rank == "NFLT"
387
189
  count = 3
190
+ level = :n
191
+ :f
388
192
  end
193
+ count ||= 1
389
194
 
390
195
  final_svg << USPSFlags::Core.field(style: style, color: color) if field
391
196
 
@@ -393,7 +198,7 @@ class USPSFlags::Generate
393
198
 
394
199
  if type == :n && count == 3
395
200
  # The side C/C tridents are angled 45 degrees, and intersect the central one at 1/3 up from the bottom
396
- trident = USPSFlags::Core.trident(type, color: (field ? :white : :blue))
201
+ trident = USPSFlags::Core.trident(type, color: trident_color)
397
202
  x_distance = USPSFlags::Config::BASE_FLY*4/39
398
203
  y_distance = USPSFlags::Config::BASE_FLY*5/78
399
204
  final_svg << "<g transform=\"translate(-#{x_distance}, #{y_distance})\"><g transform=\"rotate(-45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})\">\n#{trident}</g></g>"
@@ -401,13 +206,13 @@ class USPSFlags::Generate
401
206
  final_svg << "<g transform=\"translate(#{x_distance}, #{y_distance})\"><g transform=\"rotate(45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})\">\n#{trident}</g></g>"
402
207
  elsif type == :n && count == 2
403
208
  # V/C tridents are angled 45 degrees, and intersect at 15/32 up from the bottom
404
- trident = USPSFlags::Core.trident(type, color: (field ? :white : :red))
209
+ trident = USPSFlags::Core.trident(type, color: trident_color)
405
210
  x_distance = USPSFlags::Config::BASE_FLY*4/55
406
211
  final_svg << "<g transform=\"translate(-#{x_distance})\"><g transform=\"rotate(-45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})\">\n#{trident}</g></g>"
407
212
  final_svg << "<g transform=\"translate(#{x_distance})\"><g transform=\"rotate(45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})\">\n#{trident}</g></g>"
408
213
  elsif [:s, :d].include?(type) && count == 3
409
214
  # Cdr and D/C tridents are spaced 1/2 the fly apart with the central one 1/4 the fly above the sides
410
- trident = USPSFlags::Core.trident(type, color: (field ? :white : :blue), field_color: color)
215
+ trident = USPSFlags::Core.trident(type, color: trident_color, field_color: color)
411
216
  x_distance = USPSFlags::Config::BASE_FLY/4
412
217
  y_distance = USPSFlags::Config::BASE_FLY/16
413
218
  final_svg << "<g transform=\"translate(-#{x_distance}, #{y_distance})\">\n#{trident}</g>"
@@ -415,7 +220,7 @@ class USPSFlags::Generate
415
220
  final_svg << "<g transform=\"translate(#{x_distance}, #{y_distance})\">\n#{trident}</g>"
416
221
  elsif [:s, :d].include?(type) && count == 2
417
222
  # Lt/C and D/Lt/C tridents are spaced 1/3 the fly apart
418
- trident = USPSFlags::Core.trident(type, color: (field ? :white : :red), field_color: color)
223
+ trident = USPSFlags::Core.trident(type, color: trident_color, field_color: color)
419
224
  x_distance = USPSFlags::Config::BASE_FLY/6
420
225
  final_svg << "<g transform=\"translate(-#{x_distance})\">\n#{trident}</g>"
421
226
  final_svg << "<g transform=\"translate(#{x_distance})\">\n#{trident}</g>"
@@ -437,22 +242,8 @@ class USPSFlags::Generate
437
242
  final_svg << "<g transform=\"scale(#{Rational(USPSFlags::Config::BASE_FLY/3000).to_f})\">"
438
243
  case type
439
244
  when :a
440
- level = case count
441
- when 1
442
- :d
443
- when 2
444
- :n
445
- end
446
245
  final_svg << USPSFlags::Core.binoculars(level)
447
246
  when :f
448
- level = case count
449
- when 1
450
- :s
451
- when 2
452
- :d
453
- when 3
454
- :n
455
- end
456
247
  final_svg << USPSFlags::Core.trumpet(level)
457
248
  when :fc
458
249
  final_svg << USPSFlags::Core.anchor
@@ -552,4 +343,126 @@ class USPSFlags::Generate
552
343
  end
553
344
  final_svg
554
345
  end
346
+
347
+ private
348
+ def self.remove_static_files
349
+ ::FileUtils.rm_rf(Dir.glob("#{USPSFlags::Config.flags_dir}/SVG/*"))
350
+ ::FileUtils.rm_rf(Dir.glob("#{USPSFlags::Config.flags_dir}/PNG/*"))
351
+ ::FileUtils.rm_rf(Dir.glob("#{USPSFlags::Config.flags_dir}/ZIP/*"))
352
+ ::FileUtils.mkdir_p("#{USPSFlags::Config.flags_dir}/SVG/insignia")
353
+ ::FileUtils.mkdir_p("#{USPSFlags::Config.flags_dir}/PNG/insignia")
354
+ puts "Cleared previous files."
355
+ end
356
+
357
+ def self.generate_static_images_for(flag, svg: true, png: true)
358
+ start_time = Time.now
359
+ USPSFlags::Helpers.log " | | _ _ _ _ _ | \r".rjust(max_length+31, " ")
360
+ flag = flag.upcase
361
+ USPSFlags::Helpers.log "#{flag.rjust(max_length)} |"
362
+
363
+ svg_file = "#{USPSFlags::Config.flags_dir}/SVG/#{flag}.svg"
364
+ png_file = "#{USPSFlags::Config.flags_dir}/PNG/#{flag}.png"
365
+
366
+ svg_ins_file = "#{USPSFlags::Config.flags_dir}/SVG/insignia/#{flag}.svg"
367
+ png_ins_file = "#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.png"
368
+
369
+ past = (flag[0] == "P" && flag != "PORTCAP")
370
+
371
+ if svg
372
+ self.generate_static_svg(flag, svg_file)
373
+ else
374
+ USPSFlags::Helpers.log "-"
375
+ end
376
+
377
+ if png
378
+ self.generate_static_png(flag, png_file)
379
+ else
380
+ USPSFlags::Helpers.log "- "
381
+ end
382
+ run_time = (Time.now - start_time).round(4).to_s[(0..5)].ljust(6, "0")
383
+ USPSFlags::Helpers.log " | #{run_time} s\n"
384
+ end
385
+
386
+ def self.generate_static_svg(flag, svg_file)
387
+ begin
388
+ USPSFlags::Helpers.log " "
389
+ self.get flag, outfile: svg_file, scale: 1
390
+ USPSFlags::Helpers.log "S"
391
+ if past || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
392
+ USPSFlags::Helpers.log "-"
393
+ else
394
+ self.get flag, field: false, outfile: svg_ins_file, scale: 1
395
+ USPSFlags::Helpers.log "I"
396
+ end
397
+ rescue => e
398
+ USPSFlags::Helpers.log "x -> #{e.message}"
399
+ end
400
+ end
401
+
402
+ def self.generate_static_png(flag, png_file)
403
+ USPSFlags::Helpers.log " | "
404
+ begin
405
+ USPSFlags::Helpers.log "…\b"
406
+ USPSFlags::Generate.png(File.read(svg_file), outfile: png_file) unless ::File.exists?(png_file)
407
+ USPSFlags::Helpers.log "F"
408
+ if past || !insignia_flags.include?(flag)
409
+ USPSFlags::Helpers.log "-"
410
+ else
411
+ USPSFlags::Helpers.log "…\b"
412
+ USPSFlags::Generate.png(File.read(svg_ins_file), outfile: png_ins_file, trim: true) unless ::File.exists?(png_ins_file)
413
+ USPSFlags::Helpers.log "I"
414
+ end
415
+ sizes = {1500 => "H", 1000 => "K", 500 => "D", "thumb" => "T"}
416
+ sizes.keys.each do |size|
417
+ if ::File.exists?("#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size}.png")
418
+ USPSFlags::Helpers.log "."
419
+ else
420
+ USPSFlags::Helpers.log "…\b"
421
+ if size == "thumb"
422
+ size_key = size
423
+ size = case flag
424
+ when "ENSIGN"
425
+ 200
426
+ when "US"
427
+ 300
428
+ else
429
+ 150
430
+ end
431
+ else
432
+ size_key = size
433
+ end
434
+ MiniMagick::Tool::Convert.new do |convert|
435
+ convert << "-background" << "none"
436
+ convert << "-format" << "png"
437
+ convert << "-resize" << "#{size}"
438
+ convert << png_file
439
+ convert << "#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size_key}.png"
440
+ end
441
+ USPSFlags::Helpers.log sizes[size_key]
442
+
443
+ if ::File.exists?(png_ins_file)
444
+ if ::File.exists?("#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size}.png")
445
+ USPSFlags::Helpers.log "."
446
+ elsif MiniMagick::Image.open(png_ins_file)[:width] > size
447
+ USPSFlags::Helpers.log "…\b"
448
+ MiniMagick::Tool::Convert.new do |convert|
449
+ convert << "-background" << "none"
450
+ convert << "-format" << "png"
451
+ convert << "-resize" << "#{size}"
452
+ convert << png_ins_file
453
+ convert << "#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size_key}.png"
454
+ end
455
+ USPSFlags::Helpers.log "i"
456
+ else
457
+ USPSFlags::Helpers.log "+"
458
+ end
459
+ else
460
+ USPSFlags::Helpers.log "-"
461
+ end
462
+ end
463
+ end
464
+ rescue => e
465
+ USPSFlags::Helpers.log "x -> #{e.message}"
466
+ end
467
+ end
555
468
  end
@@ -13,34 +13,49 @@ class USPSFlags::Helpers
13
13
  # @option type [Symbol] :us US flag
14
14
  # @return [Array] Valid options for flag generation (based on the provided type).
15
15
  def self.valid_flags(type = :all)
16
- squadron = %w[
16
+ squadron_past = %w[
17
17
  PLTC
18
18
  PC
19
+ ]
20
+
21
+ squadron_elected = %w[
22
+ 1LT
23
+ LTC
24
+ CDR
25
+ ]
26
+
27
+ squadron_swallowtail = %w[
19
28
  PORTCAP
20
29
  FLEETCAP
21
30
  LT
22
31
  FLT
23
- 1LT
24
- LTC
25
- CDR
26
32
  ]
27
33
 
28
- district = %w[
34
+ district_past = %w[
29
35
  PDLTC
30
36
  PDC
31
- DLT
32
- DAIDE
33
- DFLT
37
+ ]
38
+
39
+ district_elected = %w[
34
40
  D1LT
35
41
  DLTC
36
42
  DC
37
43
  ]
38
44
 
39
- national = %w[
45
+ district_swallowtail = %w[
46
+ DLT
47
+ DAIDE
48
+ DFLT
49
+ ]
50
+
51
+ national_past = %w[
40
52
  PSTFC
41
53
  PRC
42
54
  PVC
43
55
  PCC
56
+ ]
57
+
58
+ national_elected = %w[
44
59
  NAIDE
45
60
  NFLT
46
61
  STFC
@@ -49,17 +64,6 @@ class USPSFlags::Helpers
49
64
  CC
50
65
  ]
51
66
 
52
- past = %w[
53
- PLTC
54
- PC
55
- PDLTC
56
- PDC
57
- PSTFC
58
- PRC
59
- PVC
60
- PCC
61
- ]
62
-
63
67
  special = %w[
64
68
  CRUISE
65
69
  OIC
@@ -71,6 +75,11 @@ class USPSFlags::Helpers
71
75
  US
72
76
  ]
73
77
 
78
+ squadron = squadron_past + squadron_elected + squadron_swallowtail
79
+ district = district_past + district_elected + district_swallowtail
80
+ national = national_past + national_elected
81
+ past = squadron_past + district_past + national_past
82
+
74
83
  case type
75
84
  when :all
76
85
  squadron + district + national + special + us
@@ -88,6 +97,18 @@ class USPSFlags::Helpers
88
97
  special
89
98
  when :us
90
99
  us
100
+ when :past
101
+ past
102
+ when :swallowtail
103
+ past + squadron_swallowtail + district_swallowtail
104
+ when :bridge
105
+ squadron_elected.last(2) + squadron_past.last(2) +
106
+ district_elected.last(2) + district_past.last(2) +
107
+ national_elected.last(2) + national_past.last(2)
108
+ when :command
109
+ [squadron_elected.last, squadron_past.last,
110
+ district_elected.last, district_past.last,
111
+ national_elected.last, national_past.last]
91
112
  end
92
113
  end
93
114
 
@@ -3,14 +3,7 @@ Coveralls.wear!
3
3
  require 'bundler/setup'
4
4
  Bundler.setup
5
5
 
6
- require 'usps_flags' # Contains direct SVG matching
7
- # require 'fileutils'
8
- # require 'zip'
9
- # require 'mini_magick'
10
- require 'usps_flags/config'
11
- require 'usps_flags/helpers'
12
- require 'usps_flags/core' # Contains direct SVG matching
13
- require 'usps_flags/generate'
6
+ require 'usps_flags'
14
7
 
15
8
  RSpec.configure do |config|
16
9
  # some (optional) config here
@@ -1,8 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe USPSFlags::Generate do
4
- it "should get the correct flag" do
4
+ it "should generate a flag with the correct size" do
5
5
  expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("width=\"1024pt\" height=\"682pt\" viewBox=\"0 0 3072 2048\"")
6
+ end
7
+
8
+ it "should generate a flag with the correct field" do
6
9
  expect(USPSFlags::Generate.get("LtC", outfile: "")).to include(
7
10
  <<~SVG
8
11
  <path d="M 0 0
@@ -13,7 +16,13 @@ describe USPSFlags::Generate do
13
16
  " fill="#BF0D3E" />
14
17
  SVG
15
18
  )
19
+ end
20
+
21
+ it "should generate a flag with the correct starting position" do
16
22
  expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("<path d=\"M 1536 512")
23
+ end
24
+
25
+ it "should generate a flag with the correct trident transformations" do
17
26
  expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("<g transform=\"translate(-512)\">")
18
27
  expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("<g transform=\"translate(512)\">")
19
28
  end
@@ -7,7 +7,7 @@ describe USPSFlags::Helpers do
7
7
  end
8
8
 
9
9
  it "should return all officer flags but nothing else when given type :officer" do
10
- expect(USPSFlags::Helpers.valid_flags(:officer)).to eql(%w[PLTC PC PORTCAP FLEETCAP LT FLT 1LT LTC CDR PDLTC PDC DLT DAIDE DFLT D1LT DLTC DC PSTFC PRC PVC PCC NAIDE NFLT STFC RC VC CC])
10
+ expect(USPSFlags::Helpers.valid_flags(:officer).sort).to eql(%w[PLTC PC PORTCAP FLEETCAP LT FLT 1LT LTC CDR PDLTC PDC DLT DAIDE DFLT D1LT DLTC DC PSTFC PRC PVC PCC NAIDE NFLT STFC RC VC CC].sort)
11
11
  end
12
12
  end
13
13
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'usps_flags'
3
- s.version = '0.1.24'
3
+ s.version = '0.1.25'
4
4
  s.date = '2017-10-31'
5
5
  s.summary = 'Flag generator for United States Power Squadrons'
6
6
  s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
metadata.gz.sig CHANGED
Binary file