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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +87 -0
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +2 -2
  5. data/Rakefile +4 -2
  6. data/lib/rational.rb +3 -1
  7. data/lib/usps_flags.rb +15 -17
  8. data/lib/usps_flags/config.rb +32 -29
  9. data/lib/usps_flags/core.rb +11 -9
  10. data/lib/usps_flags/core/ensign.rb +20 -17
  11. data/lib/usps_flags/core/field.rb +33 -30
  12. data/lib/usps_flags/core/footer.rb +2 -0
  13. data/lib/usps_flags/core/headers.rb +11 -8
  14. data/lib/usps_flags/core/icons.rb +14 -0
  15. data/lib/usps_flags/core/{anchor.rb → icons/anchor.rb} +7 -5
  16. data/lib/usps_flags/core/{binoculars.rb → icons/binoculars.rb} +7 -5
  17. data/lib/usps_flags/core/{lighthouse.rb → icons/lighthouse.rb} +3 -1
  18. data/lib/usps_flags/core/{star.rb → icons/star.rb} +3 -1
  19. data/lib/usps_flags/core/{trident.rb → icons/trident.rb} +29 -25
  20. data/lib/usps_flags/core/{trumpet.rb → icons/trumpet.rb} +3 -1
  21. data/lib/usps_flags/core/pennant.rb +20 -17
  22. data/lib/usps_flags/core/trident_spec.rb +62 -174
  23. data/lib/usps_flags/core/trident_specs.rb +14 -0
  24. data/lib/usps_flags/core/trident_specs/base.rb +15 -0
  25. data/lib/usps_flags/core/trident_specs/circle.rb +51 -0
  26. data/lib/usps_flags/core/trident_specs/delta.rb +68 -0
  27. data/lib/usps_flags/core/trident_specs/header.rb +65 -0
  28. data/lib/usps_flags/core/trident_specs/long.rb +54 -0
  29. data/lib/usps_flags/core/trident_specs/short.rb +176 -0
  30. data/lib/usps_flags/core/tridents.rb +16 -14
  31. data/lib/usps_flags/core/us.rb +9 -7
  32. data/lib/usps_flags/core/wheel.rb +2 -0
  33. data/lib/usps_flags/errors.rb +16 -4
  34. data/lib/usps_flags/generate.rb +48 -44
  35. data/lib/usps_flags/generate/flag.rb +33 -30
  36. data/lib/usps_flags/helpers.rb +48 -63
  37. data/lib/usps_flags/helpers/builders.rb +39 -37
  38. data/lib/usps_flags/helpers/spec_arrows.rb +16 -13
  39. data/spec/rational_spec.rb +9 -7
  40. data/spec/spec_helper.rb +5 -3
  41. data/spec/usps_flags/config_spec.rb +15 -13
  42. data/spec/usps_flags/core_spec.rb +52 -51
  43. data/spec/usps_flags/generate_spec.rb +70 -60
  44. data/spec/usps_flags/helpers_spec.rb +12 -10
  45. data/spec/usps_flags_spec.rb +22 -20
  46. data/usps_flags.gemspec +4 -2
  47. metadata +31 -21
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # SVG generators for multiple tridents.
2
4
  #
3
5
  # These methods should never need to be called directly.
@@ -7,33 +9,33 @@ class USPSFlags::Core::Tridents
7
9
  def cc(type, trident_color:)
8
10
  # The side C/C tridents are angled 45 degrees, and intersect the central one at 1/3 up from the bottom
9
11
  trident = USPSFlags::Core.trident(type, color: trident_color)
10
- x_distance = USPSFlags::Config::BASE_FLY*4/39
11
- y_distance = USPSFlags::Config::BASE_FLY*5/78
12
+ x_distance = USPSFlags::Config::BASE_FLY * 4 / 39
13
+ y_distance = USPSFlags::Config::BASE_FLY * 5 / 78
12
14
  <<~SVG
13
- <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>
15
+ <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>
14
16
  \n#{trident}
15
- <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>
17
+ <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>
16
18
  SVG
17
19
  end
18
20
 
19
21
  def vc(type, trident_color:)
20
22
  # V/C tridents are angled 45 degrees, and intersect at 15/32 up from the bottom
21
23
  trident = USPSFlags::Core.trident(type, color: trident_color)
22
- x_distance = USPSFlags::Config::BASE_FLY*4/55
24
+ x_distance = USPSFlags::Config::BASE_FLY * 4 / 55
23
25
  <<~SVG
24
- <g transform="translate(-#{x_distance})"><g transform="rotate(-45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})">\n#{trident}</g></g>
25
- <g transform="translate(#{x_distance})"><g transform="rotate(45, #{USPSFlags::Config::BASE_FLY/2}, #{USPSFlags::Config::BASE_HOIST/2})">\n#{trident}</g></g>
26
+ <g transform="translate(-#{x_distance})"><g transform="rotate(-45, #{USPSFlags::Config::BASE_FLY / 2}, #{USPSFlags::Config::BASE_HOIST / 2})">\n#{trident}</g></g>
27
+ <g transform="translate(#{x_distance})"><g transform="rotate(45, #{USPSFlags::Config::BASE_FLY / 2}, #{USPSFlags::Config::BASE_HOIST / 2})">\n#{trident}</g></g>
26
28
  SVG
27
29
  end
28
30
 
29
31
  def three(type, trident_color:, field_color:)
30
32
  # Cdr and D/C tridents are spaced 1/2 the fly apart with the central one 1/4 the fly above the sides
31
33
  trident = USPSFlags::Core.trident(type, color: trident_color, field_color: field_color)
32
- x_distance = USPSFlags::Config::BASE_FLY/4
33
- y_distance = USPSFlags::Config::BASE_FLY/16
34
+ x_distance = USPSFlags::Config::BASE_FLY / 4
35
+ y_distance = USPSFlags::Config::BASE_FLY / 16
34
36
  <<~SVG
35
37
  <g transform="translate(-#{x_distance}, #{y_distance})">\n#{trident}</g>
36
- <g transform="translate(0, -#{y_distance+1})">\n#{trident}</g>
38
+ <g transform="translate(0, -#{y_distance + 1})">\n#{trident}</g>
37
39
  <g transform="translate(#{x_distance}, #{y_distance})">\n#{trident}</g>
38
40
  SVG
39
41
  end
@@ -41,7 +43,7 @@ class USPSFlags::Core::Tridents
41
43
  def two(type, trident_color:, field_color:)
42
44
  # Lt/C and D/Lt/C tridents are spaced 1/3 the fly apart
43
45
  trident = USPSFlags::Core.trident(type, color: trident_color, field_color: field_color)
44
- x_distance = USPSFlags::Config::BASE_FLY/6
46
+ x_distance = USPSFlags::Config::BASE_FLY / 6
45
47
  <<~SVG
46
48
  <g transform="translate(-#{x_distance})">\n#{trident}</g>
47
49
  <g transform="translate(#{x_distance})">\n#{trident}</g>
@@ -50,11 +52,11 @@ class USPSFlags::Core::Tridents
50
52
 
51
53
  def offset(type, field_color:, field: true)
52
54
  # Swallowtail tridents need to move towards the hoist due to the tails
53
- x_distance = USPSFlags::Config::BASE_FLY/10 if field
54
- svg = ""
55
+ x_distance = USPSFlags::Config::BASE_FLY / 10 if field
56
+ svg = ''
55
57
  svg << "<g transform=\"translate(-#{x_distance})\">" if field
56
58
  svg << USPSFlags::Core.trident(type, field_color: field_color, color: :red)
57
- svg << "</g>" if field
59
+ svg << '</g>' if field
58
60
  svg
59
61
  end
60
62
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # Core SVG data for the US Ensign.
2
4
  #
3
5
  # This class should never need to be called directly.
@@ -5,10 +7,10 @@
5
7
  class USPSFlags::Core::US
6
8
  def svg
7
9
  @base_hoist = 2000.to_f
8
- @base_fly = @base_hoist*1.91
10
+ @base_fly = @base_hoist * 1.91
9
11
 
10
- @canton_hoist = @base_hoist*7/13
11
- @canton_fly = @canton_hoist*Math.sqrt(2)
12
+ @canton_hoist = @base_hoist * 7 / 13
13
+ @canton_fly = @canton_hoist * Math.sqrt(2)
12
14
 
13
15
  @star_offset = 20 # Half of scaled star height
14
16
 
@@ -24,7 +26,7 @@ class USPSFlags::Core::US
24
26
  svg
25
27
  end
26
28
 
27
- private
29
+ private
28
30
 
29
31
  def defs
30
32
  File.read("#{File.dirname(__dir__)}/core/us_defs.svg.partial").gsub('STAR', USPSFlags::Core.star)
@@ -40,12 +42,12 @@ class USPSFlags::Core::US
40
42
  even: (2..10).step(2).to_a
41
43
  }
42
44
 
43
- svg = ""
45
+ svg = ''
44
46
  %i[odd even].each do |type|
45
47
  rows[type].each do |r|
46
48
  columns[type].each do |c|
47
49
  svg << <<~SVG
48
- <g transform="translate(#{@canton_fly*c/12}, #{@star_offset+@canton_hoist*r/10})"><g><use href="#star" /></g></g>
50
+ <g transform="translate(#{@canton_fly * c / 12}, #{@star_offset + @canton_hoist * r / 10})"><g><use href="#star" /></g></g>
49
51
  SVG
50
52
  end
51
53
  end
@@ -56,7 +58,7 @@ class USPSFlags::Core::US
56
58
  def stripes
57
59
  s = (0..12).map do |i|
58
60
  color = i.even? ? 'red' : 'white'
59
- "<use href=\"##{color}-stripe\" y=\"#{@base_hoist*i/13}\" />"
61
+ "<use href=\"##{color}-stripe\" y=\"#{@base_hoist * i / 13}\" />"
60
62
  end
61
63
 
62
64
  s.join("\n") + "\n<rect y=\"0\" width=\"#{@canton_fly}\" height=\"#{@canton_hoist}\" fill=\"#{USPSFlags::Config::OLD_GLORY_BLUE}\" />\n"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # Core SVG data for the USPS Wheel logo.
2
4
  #
3
5
  # This class should never need to be called directly.
@@ -1,28 +1,40 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # Custom errors.
2
4
  #
3
5
  # @private
4
6
  module USPSFlags::Errors
5
7
  class PNGGenerationError < StandardError
6
- def initialize(msg = "There was an error generating the PNG file.", svg: "")
8
+ attr_reader :svg
9
+
10
+ def initialize(msg = 'There was an error generating the PNG file.', svg: '')
7
11
  super(msg)
12
+ @svg = svg
8
13
  end
9
14
  end
10
15
 
11
16
  class PNGConversionError < StandardError
12
- def initialize(msg = "There was an error converting the PNG file.")
17
+ def initialize(msg = 'There was an error converting the PNG file.')
13
18
  super(msg)
14
19
  end
15
20
  end
16
21
 
17
22
  class StaticFilesGenerationError < StandardError
18
- def initialize(msg = "There was an error generating the static files.", cause: nil)
23
+ attr_reader :cause
24
+
25
+ def initialize(msg = 'There was an error generating the static files.', cause: nil)
19
26
  super(msg)
27
+ @cause = cause
20
28
  end
21
29
  end
22
30
 
23
31
  class ZipGenerationError < StandardError
24
- def initialize(msg = "There was an error generating the zip file.", type: nil, cause: nil)
32
+ attr_reader :type, :cause
33
+
34
+ def initialize(msg = 'There was an error generating the zip file.', type: nil, cause: nil)
25
35
  super(msg)
36
+ @type = type
37
+ @cause = cause
26
38
  end
27
39
  end
28
40
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # Controller class for generating files.
2
4
  class USPSFlags::Generate
3
5
  class << self
@@ -9,17 +11,17 @@ class USPSFlags::Generate
9
11
  # @param [String] scale The image scale divisor factor.
10
12
  # @return [String] Returns the SVG data.
11
13
  def svg(flag, outfile: nil, scale: nil, field: true)
12
- flag = flag.upcase.delete("/", "_", "PENNANT")
14
+ flag = flag.upcase.delete('/', '_', 'PENNANT')
13
15
 
14
16
  USPSFlags::Helpers.ensure_dir_for_file(outfile)
15
17
 
16
- if ["CRUISE", "OIC"].include?(flag)
18
+ if ['CRUISE', 'OIC'].include?(flag)
17
19
  USPSFlags::Generate::Flag.pennant(type: flag, outfile: outfile, scale: scale)
18
- elsif flag == "ENSIGN"
20
+ elsif flag == 'ENSIGN'
19
21
  USPSFlags::Generate::Flag.ensign(outfile: outfile, scale: scale)
20
- elsif flag == "US"
22
+ elsif flag == 'US'
21
23
  USPSFlags::Generate::Flag.us(outfile: outfile, scale: scale)
22
- elsif flag == "WHEEL"
24
+ elsif flag == 'WHEEL'
23
25
  USPSFlags::Generate::Flag.wheel(outfile: outfile, scale: scale)
24
26
  else
25
27
  USPSFlags::Generate::Flag.officer(rank: flag, outfile: outfile, scale: scale, field: field)
@@ -33,16 +35,16 @@ class USPSFlags::Generate
33
35
  # @param [Boolean] trim Whether to trim the generated PNG file of excess transparency.
34
36
  # @param [String] background Background color. Defaults to 'none' (transparent).
35
37
  def png(svg, outfile: nil, trim: false, background: 'none')
36
- raise USPSFlags::Errors::PNGGenerationError, svg: svg if outfile.nil? || outfile.empty?
38
+ raise USPSFlags::Errors::PNGGenerationError.new(svg: svg) if outfile.nil? || outfile.empty?
37
39
 
38
40
  set_temp_svg(svg)
39
41
 
40
42
  USPSFlags::Helpers.ensure_dir_for_file(outfile)
41
43
 
42
44
  MiniMagick::Tool::Convert.new do |convert|
43
- convert << "-background" << background
44
- convert << "-format" << "png"
45
- convert << "-trim" if trim
45
+ convert << '-background' << background
46
+ convert << '-format' << 'png'
47
+ convert << '-trim' if trim
46
48
  convert << @temp_svg_path
47
49
  convert << outfile
48
50
  end
@@ -57,7 +59,7 @@ class USPSFlags::Generate
57
59
  # @param [Boolean] zips Whether to create zip archives for all images created. Does not create a zip for skipped formats.
58
60
  # @param [Boolean] reset Whether to delete all previous files before generating new files.
59
61
  def all(svg: true, png: true, zips: true, reset: true)
60
- raise USPSFlags::Errors::StaticFilesGenerationError, "At least one argument switch must be true out of [svg, png, zips, reset]." unless svg || png || zips || reset
62
+ raise USPSFlags::Errors::StaticFilesGenerationError, 'At least one argument switch must be true out of [svg, png, zips, reset].' unless svg || png || zips || reset
61
63
 
62
64
  overall_start_time = Time.now
63
65
  remove_static_files if reset
@@ -71,9 +73,10 @@ class USPSFlags::Generate
71
73
  # @param [Boolean] svg Generate zip archive of SVG images.
72
74
  # @param [Boolean] png Generate zip archive of PNG images.
73
75
  def zips(svg: true, png: true)
74
- raise USPSFlags::Errors::ZipGenerationError, "At least one argument switch must be true out of [svg, png]." unless svg || png
75
- generate_zip("svg") if svg
76
- generate_zip("png") if png
76
+ raise USPSFlags::Errors::ZipGenerationError, 'At least one argument switch must be true out of [svg, png].' unless svg || png
77
+
78
+ generate_zip('svg') if svg
79
+ generate_zip('png') if png
77
80
  end
78
81
 
79
82
  # Generate static image files.
@@ -95,44 +98,45 @@ class USPSFlags::Generate
95
98
  # @param [String] scale The image scale divisor factor.
96
99
  # @return [String] Returns the SVG data.
97
100
  def spec(outfile: nil, fly: USPSFlags::Config::BASE_FLY, unit: nil, scale: nil, scaled_border: false)
98
- svg = ""
99
- svg << USPSFlags::Core.headers(scale: scale, title: "USPS Trident Specifications")
101
+ svg = ''
102
+ svg << USPSFlags::Core.headers(scale: scale, title: 'USPS Trident Specifications')
100
103
  svg << USPSFlags::Core.trident_spec(fly: fly, unit: unit, scaled_border: scaled_border)
101
104
  svg << USPSFlags::Core.footer
102
105
 
103
106
  USPSFlags::Helpers.output(svg, outfile: outfile)
104
107
  end
105
108
 
106
- private
109
+ private
110
+
107
111
  def remove_static_files
108
- ["SVG", "PNG", "ZIP"].each do |dir|
112
+ ['SVG', 'PNG', 'ZIP'].each do |dir|
109
113
  dir_path = "#{USPSFlags.configuration.flags_dir}/#{dir}"
110
114
  ::FileUtils.rm_rf(::Dir.glob("#{dir_path}/*")) if ::Dir.exist?(dir_path)
111
115
  end
112
- ["SVG/insignia", "PNG/insignia"].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags.configuration.flags_dir}/#{dir}") }
116
+ ['SVG/insignia', 'PNG/insignia'].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags.configuration.flags_dir}/#{dir}") }
113
117
  USPSFlags::Helpers.log "\n - Cleared previous files.\n"
114
118
  end
115
119
 
116
120
  def set_file_paths
117
121
  @svg_file = "#{USPSFlags.configuration.flags_dir}/SVG/#{@flag}.svg"
118
- @png_file = @svg_file.gsub("/SVG/", "/PNG/").gsub(".svg", ".png")
119
- @svg_ins_file = @svg_file.gsub("/SVG/", "/SVG/insignia/")
120
- @png_ins_file = @svg_file.gsub("/SVG/", "/PNG/insignia/").gsub(".svg", ".png")
122
+ @png_file = @svg_file.gsub('/SVG/', '/PNG/').gsub('.svg', '.png')
123
+ @svg_ins_file = @svg_file.gsub('/SVG/', '/SVG/insignia/')
124
+ @png_ins_file = @svg_file.gsub('/SVG/', '/PNG/insignia/').gsub('.svg', '.png')
121
125
  [@svg_file, @png_file, @svg_ins_file, @png_ins_file]
122
126
  end
123
127
 
124
128
  def static_generation_header
125
129
  puts "\nSVGs generate a single file.",
126
- "PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.",
127
- "Corresponding rank insignia (including smaller sizes) are also generated, as appropriate."
130
+ 'PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.',
131
+ 'Corresponding rank insignia (including smaller sizes) are also generated, as appropriate.'
128
132
  USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags.configuration.flags_dir}\n"
129
133
  USPSFlags::Helpers.log "\n#{Time.now.strftime('%Y%m%d.%H%M%S%z')} – Generating static files...\n\n"
130
- USPSFlags::Helpers.log "Flag | SVG | PNG | Run time\n".rjust(USPSFlags::Helpers.max_flag_name_length+31),
131
- "\n".rjust(USPSFlags::Helpers.max_flag_name_length+32, "-")
134
+ USPSFlags::Helpers.log "Flag | SVG | PNG | Run time\n".rjust(USPSFlags::Helpers.max_flag_name_length + 31),
135
+ "\n".rjust(USPSFlags::Helpers.max_flag_name_length + 32, '-')
132
136
  end
133
137
 
134
138
  def generate_zip(type)
135
- raise USPSFlags::Errors::ZipGenerationError, "Flags directory not found." unless ::Dir.exist?("#{USPSFlags.configuration.flags_dir}/ZIP")
139
+ raise USPSFlags::Errors::ZipGenerationError, 'Flags directory not found.' unless ::Dir.exist?("#{USPSFlags.configuration.flags_dir}/ZIP")
136
140
 
137
141
  zip = "#{USPSFlags.configuration.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
138
142
  ::File.delete(zip) if ::File.exist?(zip)
@@ -146,8 +150,8 @@ class USPSFlags::Generate
146
150
  end
147
151
 
148
152
  def add_to_zip(z, f)
149
- filename = f.split("/").last
150
- filename = "insignia/#{filename}" if f.split("/").last(2).first == "insignia"
153
+ filename = f.split('/').last
154
+ filename = "insignia/#{filename}" if f.split('/').last(2).first == 'insignia'
151
155
  z.add(filename, f)
152
156
  end
153
157
 
@@ -158,16 +162,16 @@ class USPSFlags::Generate
158
162
 
159
163
  set_file_paths
160
164
 
161
- svg ? generate_static_svg : USPSFlags::Helpers.log("-")
162
- png ? generate_static_png : USPSFlags::Helpers.log("- ")
165
+ svg ? generate_static_svg : USPSFlags::Helpers.log('-')
166
+ png ? generate_static_png : USPSFlags::Helpers.log('- ')
163
167
 
164
- run_time = (Time.now - start_time).round(4).to_s[(0..5)].ljust(6, "0")
168
+ run_time = (Time.now - start_time).round(4).to_s[(0..5)].ljust(6, '0')
165
169
  USPSFlags::Helpers.log " | #{run_time} s\n"
166
170
  end
167
171
 
168
172
  def generate_static_svg
169
- USPSFlags::Helpers.log " "
170
-
173
+ USPSFlags::Helpers.log ' '
174
+
171
175
  generate_regular_svg
172
176
  generate_insignia_svg
173
177
  end
@@ -176,19 +180,19 @@ class USPSFlags::Generate
176
180
  return if file_found?(@svg_file)
177
181
 
178
182
  svg @flag, outfile: @svg_file, scale: 1
179
- USPSFlags::Helpers.log "S"
183
+ USPSFlags::Helpers.log 'S'
180
184
  end
181
185
 
182
186
  def generate_insignia_svg
183
187
  return if no_insignia?
184
188
 
185
189
  svg @flag, field: false, outfile: @svg_ins_file, scale: 1
186
- USPSFlags::Helpers.log "I"
190
+ USPSFlags::Helpers.log 'I'
187
191
  end
188
192
 
189
193
  def set_temp_svg(svg)
190
194
  @temp_svg_path = "#{USPSFlags.configuration.flags_dir}/temp.svg"
191
- temp_svg = ::File.new(@temp_svg_path, "w+")
195
+ temp_svg = ::File.new(@temp_svg_path, 'w+')
192
196
  temp_svg.write(svg)
193
197
  temp_svg.flush
194
198
  @temp_svg_path
@@ -199,7 +203,7 @@ class USPSFlags::Generate
199
203
  end
200
204
 
201
205
  def generate_static_png
202
- USPSFlags::Helpers.log " | "
206
+ USPSFlags::Helpers.log ' | '
203
207
  generate_fullsize_png
204
208
  generate_fullsize_png_insignia
205
209
  generate_reduced_size_pngs
@@ -209,7 +213,7 @@ class USPSFlags::Generate
209
213
  return if file_found?(@png_file)
210
214
 
211
215
  png(File.read(@svg_file), outfile: @png_file)
212
- USPSFlags::Helpers.log "F"
216
+ USPSFlags::Helpers.log 'F'
213
217
  end
214
218
 
215
219
  def generate_fullsize_png_insignia
@@ -217,14 +221,14 @@ class USPSFlags::Generate
217
221
  return if file_found?(@png_ins_file)
218
222
 
219
223
  png(File.read(@svg_ins_file), outfile: @png_ins_file, trim: true)
220
- USPSFlags::Helpers.log "I"
224
+ USPSFlags::Helpers.log 'I'
221
225
  end
222
226
 
223
227
  def generate_reduced_size_pngs
224
228
  USPSFlags::Helpers.png_sizes.keys.each do |size|
225
229
  size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: @flag)
226
230
  @sized_png_file = "#{USPSFlags.configuration.flags_dir}/PNG/#{@flag}.#{size_key}.png"
227
- @sized_png_ins_file = @sized_png_file.gsub("/PNG/", "/PNG/insignia/")
231
+ @sized_png_ins_file = @sized_png_file.gsub('/PNG/', '/PNG/insignia/')
228
232
 
229
233
  generate_smaller_png(size, size_key)
230
234
  generate_smaller_png_insignia(size, size_key)
@@ -245,27 +249,27 @@ class USPSFlags::Generate
245
249
  return if too_big?(@png_ins_file, size)
246
250
 
247
251
  USPSFlags::Helpers.resize_png(@png_ins_file, file: "insignia/#{@flag}", size: size, size_key: size_key)
248
- USPSFlags::Helpers.log "i"
252
+ USPSFlags::Helpers.log 'i'
249
253
  end
250
254
 
251
255
  def no_insignia?
252
256
  return false if USPSFlags::Helpers.valid_flags(:insignia).include?(@flag)
253
257
 
254
- USPSFlags::Helpers.log "-"
258
+ USPSFlags::Helpers.log '-'
255
259
  true
256
260
  end
257
261
 
258
262
  def file_found?(file)
259
263
  return false unless ::File.exist?(file)
260
264
 
261
- USPSFlags::Helpers.log "."
265
+ USPSFlags::Helpers.log '.'
262
266
  true
263
267
  end
264
268
 
265
269
  def too_big?(file, size)
266
270
  return false unless size > MiniMagick::Image.open(file)[:width]
267
271
 
268
- USPSFlags::Helpers.log "+"
272
+ USPSFlags::Helpers.log '+'
269
273
  true
270
274
  end
271
275
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # SVG generators for special flags.
2
4
  #
3
5
  # These methods should never need to be called directly.
@@ -5,11 +7,12 @@
5
7
  class USPSFlags::Generate::Flag
6
8
  class << self
7
9
  def officer(rank: nil, width: USPSFlags::Config::BASE_FLY, outfile: nil, scale: nil, field: true)
8
- raise ArgumentError, "No rank specified." if rank.nil?
10
+ raise ArgumentError, 'No rank specified.' if rank.nil?
11
+
9
12
  @rank = rank.to_s.upcase
10
13
  @field = field
11
14
 
12
- svg = ""
15
+ svg = ''
13
16
  svg << USPSFlags::Core.headers(scale: scale, title: @rank)
14
17
  modify_rank_for_insignia
15
18
  @flag_details = USPSFlags::Helpers.flag_details(@rank)
@@ -21,29 +24,29 @@ class USPSFlags::Generate::Flag
21
24
 
22
25
  def special(type, level:, field: true)
23
26
  # Paths were designed for a base fly of 3000 pixels, but the base was changed for more useful fractions.
24
- svg = ""
25
- svg << "<g transform=\"translate(#{USPSFlags::Config::BASE_FLY/10})\">" unless field
26
- svg << "<g transform=\"scale(#{Rational(USPSFlags::Config::BASE_FLY,3000).to_f})\">"
27
+ svg = ''
28
+ svg << "<g transform=\"translate(#{USPSFlags::Config::BASE_FLY / 10})\">" unless field
29
+ svg << "<g transform=\"scale(#{Rational(USPSFlags::Config::BASE_FLY, 3000).to_f})\">"
27
30
  svg << case type
28
- when :a
29
- USPSFlags::Core.binoculars(level)
30
- when :f
31
- USPSFlags::Core.trumpet(level)
32
- when :fc
33
- USPSFlags::Core.anchor
34
- when :pc
35
- USPSFlags::Core.lighthouse
31
+ when :a
32
+ USPSFlags::Core.binoculars(level)
33
+ when :f
34
+ USPSFlags::Core.trumpet(level)
35
+ when :fc
36
+ USPSFlags::Core.anchor
37
+ when :pc
38
+ USPSFlags::Core.lighthouse
36
39
  end
37
- svg << "</g>"
38
- svg << "</g>" unless field
40
+ svg << '</g>'
41
+ svg << '</g>' unless field
39
42
 
40
43
  svg
41
44
  end
42
45
 
43
- def pennant(type: "CRUISE", outfile: nil, scale: nil)
46
+ def pennant(type: 'CRUISE', outfile: nil, scale: nil)
44
47
  type = type.upcase
45
- svg = ""
46
- title = { "CRUISE" => "Cruise Pennant", "OIC" => "Officer-in-Charge Pennant" }[type]
48
+ svg = ''
49
+ title = { 'CRUISE' => 'Cruise Pennant', 'OIC' => 'Officer-in-Charge Pennant' }[type]
47
50
  svg << USPSFlags::Core.headers(pennant: true, scale: scale, title: title)
48
51
  svg << USPSFlags::Core.pennant(type)
49
52
  svg << USPSFlags::Core.footer
@@ -52,8 +55,8 @@ class USPSFlags::Generate::Flag
52
55
  end
53
56
 
54
57
  def ensign(outfile: nil, scale: nil)
55
- svg = ""
56
- svg << USPSFlags::Core.headers(scale: scale, title: "USPS Ensign")
58
+ svg = ''
59
+ svg << USPSFlags::Core.headers(scale: scale, title: 'USPS Ensign')
57
60
  svg << USPSFlags::Core.ensign
58
61
  svg << USPSFlags::Core.footer
59
62
 
@@ -63,8 +66,8 @@ class USPSFlags::Generate::Flag
63
66
  def wheel(outfile: nil, scale: nil)
64
67
  width = 4327.4667
65
68
  height = 4286.9333
66
- svg = ""
67
- svg << USPSFlags::Core.headers(width: width, height: height, scale: scale, title: "USPS Ensign Wheel")
69
+ svg = ''
70
+ svg << USPSFlags::Core.headers(width: width, height: height, scale: scale, title: 'USPS Ensign Wheel')
68
71
  svg << USPSFlags::Core.wheel
69
72
  svg << USPSFlags::Core.footer
70
73
 
@@ -73,18 +76,18 @@ class USPSFlags::Generate::Flag
73
76
 
74
77
  def us(outfile: nil, scale: nil)
75
78
  base_hoist = 2000.to_f
76
- base_fly = base_hoist * 1.91
77
79
  hoist = scale.nil? ? base_hoist : (base_hoist / scale)
78
80
  fly = hoist * 1.91
79
- svg = ""
80
- svg << USPSFlags::Core.headers(width: fly, height: hoist, scale: scale, title: "US Ensign")
81
+ svg = ''
82
+ svg << USPSFlags::Core.headers(width: fly, height: hoist, scale: scale, title: 'US Ensign')
81
83
  svg << USPSFlags::Core.us
82
84
  svg << USPSFlags::Core.footer
83
85
 
84
86
  USPSFlags::Helpers.output(svg, outfile: outfile)
85
87
  end
86
88
 
87
- private
89
+ private
90
+
88
91
  def get_officer_flag
89
92
  if cc?
90
93
  USPSFlags::Core::Tridents.cc(@flag_details[:type], trident_color: @trident_color)
@@ -104,18 +107,18 @@ class USPSFlags::Generate::Flag
104
107
  end
105
108
 
106
109
  def officer_flag_body
107
- svg = ""
110
+ svg = ''
108
111
  svg << USPSFlags::Core.field(style: @flag_details[:style], color: @flag_details[:color]) if @field
109
- svg << "<g transform=\"translate(-150, 400)\"><g transform=\"scale(0.58333)\">" if @flag_details[:style] == :past
112
+ svg << '<g transform="translate(-150, 400)"><g transform="scale(0.58333)">' if @flag_details[:style] == :past
110
113
  svg << get_officer_flag
111
- svg << "</g></g>" if @flag_details[:style] == :past
114
+ svg << '</g></g>' if @flag_details[:style] == :past
112
115
  svg << USPSFlags::Core.footer
113
116
  svg
114
117
  end
115
118
 
116
119
  def modify_rank_for_insignia
117
120
  @rank.slice!(0) if !@field && USPSFlags::Helpers.valid_flags(:past).include?(@rank)
118
- @rank = "CDR" if @rank == "C"
121
+ @rank = 'CDR' if @rank == 'C'
119
122
  end
120
123
 
121
124
  def cc?