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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -11
  3. data/.travis.yml +1 -1
  4. data/Gemfile.lock +5 -2
  5. data/README.md +6 -0
  6. data/lib/usps_flags.rb +35 -44
  7. data/lib/usps_flags/config.rb +89 -87
  8. data/lib/usps_flags/core.rb +44 -42
  9. data/lib/usps_flags/core/ensign.rb +53 -49
  10. data/lib/usps_flags/core/field.rb +96 -92
  11. data/lib/usps_flags/core/footer.rb +9 -5
  12. data/lib/usps_flags/core/headers.rb +58 -48
  13. data/lib/usps_flags/core/icons.rb +11 -7
  14. data/lib/usps_flags/core/icons/anchor.rb +62 -56
  15. data/lib/usps_flags/core/icons/binoculars.rb +21 -15
  16. data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
  17. data/lib/usps_flags/core/icons/star.rb +21 -15
  18. data/lib/usps_flags/core/icons/trident.rb +136 -127
  19. data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
  20. data/lib/usps_flags/core/icons/trumpet.rb +34 -28
  21. data/lib/usps_flags/core/pennant.rb +50 -46
  22. data/lib/usps_flags/core/trident_spec.rb +135 -131
  23. data/lib/usps_flags/core/trident_specs.rb +11 -7
  24. data/lib/usps_flags/core/trident_specs/base.rb +36 -26
  25. data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
  26. data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
  27. data/lib/usps_flags/core/trident_specs/header.rb +56 -50
  28. data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
  29. data/lib/usps_flags/core/trident_specs/long.rb +41 -25
  30. data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
  31. data/lib/usps_flags/core/trident_specs/short.rb +30 -156
  32. data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
  33. data/lib/usps_flags/core/tridents.rb +54 -50
  34. data/lib/usps_flags/core/us.rb +40 -44
  35. data/lib/usps_flags/core/wheel.rb +7 -3
  36. data/lib/usps_flags/errors.rb +25 -23
  37. data/lib/usps_flags/generate.rb +111 -107
  38. data/lib/usps_flags/generate/flag.rb +160 -157
  39. data/lib/usps_flags/generate/generator_methods.rb +139 -0
  40. data/lib/usps_flags/generate/helper_methods.rb +88 -0
  41. data/lib/usps_flags/helpers.rb +163 -165
  42. data/lib/usps_flags/helpers/builders.rb +92 -85
  43. data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
  44. data/lib/usps_flags/helpers/valid_flags.rb +45 -41
  45. data/lib/usps_flags/rational.rb +35 -0
  46. data/spec/usps_flags/config_spec.rb +17 -10
  47. data/spec/usps_flags/core_spec.rb +31 -31
  48. data/spec/usps_flags/generate_spec.rb +76 -73
  49. data/spec/usps_flags/helpers_spec.rb +8 -8
  50. data/spec/usps_flags/rational_spec.rb +17 -0
  51. data/spec/usps_flags_spec.rb +19 -21
  52. data/usps_flags.gemspec +7 -6
  53. metadata +34 -10
  54. data/lib/rational.rb +0 -39
  55. data/lib/usps_flags/generate/private.rb +0 -199
  56. data/spec/rational_spec.rb +0 -19
@@ -4,24 +4,24 @@ require 'spec_helper'
4
4
 
5
5
  describe USPSFlags::Helpers do
6
6
  describe 'valid_flags' do
7
- it 'should return an Array' do
8
- expect(USPSFlags::Helpers.valid_flags).to be_an(Array)
7
+ it 'returns an Array' do
8
+ expect(described_class.valid_flags).to be_an(Array)
9
9
  end
10
10
 
11
- it 'should return all officer flags but nothing else when given type :officer' do
12
- expect(USPSFlags::Helpers.valid_flags(:officer).sort).to eql(%w[
11
+ it 'returns all officer flags but nothing else when given type :officer' do
12
+ expect(described_class.valid_flags(:officer).sort).to eql(%w[
13
13
  PLTC PC PORTCAP FLEETCAP LT FLT 1LT LTC CDR PDLTC PDC DLT DAIDE
14
14
  DFLT D1LT DLTC DC PSTFC PRC PVC PCC NAIDE NFLT STFC RC VC CC
15
15
  ].sort)
16
16
  end
17
17
 
18
- it 'should correctly generate the grid helper' do
18
+ it 'correctlies generate the grid helper' do
19
19
  expect(USPSFlags::Helpers::Builders.grid).to include(
20
20
  "<circle cx=\"0\" cy=\"0\" r=\"#{USPSFlags::Config::BASE_FLY / 60}\" fill=\"#000000\" fill-opacity=\"0.4\" />"
21
21
  )
22
22
  end
23
23
 
24
- it 'should correctly generate the locator helper' do
24
+ it 'correctlies generate the locator helper' do
25
25
  expect(USPSFlags::Helpers::Builders.locator).to include(
26
26
  "<rect x=\"0\" y=\"0\" width=\"#{USPSFlags::Config::BASE_FLY / 30}\" " \
27
27
  "height=\"#{USPSFlags::Config::BASE_FLY / 30}\" fill=\"#333333\" fill-opacity=\"0.6\" />"
@@ -30,9 +30,9 @@ describe USPSFlags::Helpers do
30
30
  end
31
31
 
32
32
  describe 'resize_png' do
33
- it 'should raise USPSFlags::Errors::PNGConversionError with invalid parameters' do
33
+ it 'raises USPSFlags::Errors::PNGConversionError with invalid parameters' do
34
34
  expect do
35
- USPSFlags::Helpers.resize_png('path/to/image.png', size: 100, size_key: 'thumb')
35
+ described_class.resize_png('path/to/image.png', size: 100, size_key: 'thumb')
36
36
  end.to raise_error(USPSFlags::Errors::PNGConversionError)
37
37
  end
38
38
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: false
2
+
3
+ require 'spec_helper'
4
+
5
+ describe USPSFlags::Rational do
6
+ it 'renders a simplified fraction as an Array' do
7
+ expect(described_class.new(Rational(4, 3)).to_simplified_a).to eql([1, Rational(1, 3)])
8
+ end
9
+
10
+ it 'renders a proper fraction as String' do
11
+ expect(described_class.new(Rational(2, 3)).to_simplified_a).to eql('2/3')
12
+ end
13
+
14
+ it 'renders a simplified fraction as a String' do
15
+ expect(described_class.new(Rational(4, 3)).to_simplified_s).to eql('1 1/3')
16
+ end
17
+ end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe USPSFlags do
6
- before(:all) do
6
+ before do
7
7
  @valid_header = <<~SVG
8
8
  <?xml version="1.0" standalone="no"?>
9
9
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
@@ -88,76 +88,74 @@ describe USPSFlags do
88
88
  </g>
89
89
  </svg>
90
90
  SVG
91
- end
92
91
 
93
- before(:each) do
94
- @flag = USPSFlags.new
92
+ @flag = described_class.new
95
93
  end
96
94
 
97
95
  describe 'constructor' do
98
- it 'should update type' do
96
+ it 'updates type' do
99
97
  @flag.type = 'LtC'
100
98
  expect(@flag.type).to eql('LtC')
101
99
  end
102
100
 
103
- it 'should update scale' do
101
+ it 'updates scale' do
104
102
  @flag.scale = 4
105
- expect(@flag.scale).to eql(4)
103
+ expect(@flag.scale).to be(4)
106
104
  end
107
105
 
108
- it 'should update field' do
106
+ it 'updates field' do
109
107
  @flag.field = false
110
- expect(@flag.field).to eql(false)
108
+ expect(@flag.field).to be(false)
111
109
  end
112
110
 
113
- it 'should update trim' do
111
+ it 'updates trim' do
114
112
  @flag.trim = true
115
- expect(@flag.trim).to eql(true)
113
+ expect(@flag.trim).to be(true)
116
114
  end
117
115
 
118
- it 'should correctly update svg_file' do
116
+ it 'correctlies update svg_file' do
119
117
  @flag.svg_file = "#{$tmp_alt_flags_dir}/SVG/output.svg"
120
118
  expect(@flag.svg_file).to eql("#{$tmp_alt_flags_dir}/SVG/output.svg")
121
119
  end
122
120
 
123
- it 'should correctly update png_file' do
121
+ it 'correctlies update png_file' do
124
122
  @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/output.png"
125
123
  expect(@flag.png_file).to eql("#{$tmp_alt_flags_dir}/PNG/output.png")
126
124
  end
127
125
 
128
126
  describe 'as configured' do
129
- before(:each) do
127
+ before do
130
128
  @flag.type = 'LtC'
131
129
  @flag.scale = 5
132
130
  @flag.svg_file = ''
133
131
  end
134
132
 
135
- it 'should construct and generate a flag with a valid header' do
133
+ it 'constructs and generate a flag with a valid header' do
136
134
  expect(@flag.svg).to include(@valid_header)
137
135
  end
138
136
 
139
- it 'should construct and generate a flag with a valid body' do
137
+ it 'constructs and generate a flag with a valid body' do
140
138
  expect(@flag.svg).to include(@valid_body)
141
139
  end
142
140
 
143
141
  describe 'png' do
144
- it 'should raise PNGGenerationError without png_file set' do
142
+ it 'raises PNGGenerationError without png_file set' do
145
143
  expect { @flag.png }.to raise_error(
146
144
  USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.'
147
145
  )
148
146
  end
149
147
 
150
148
  context 'with png_file set' do
151
- before(:each) do
149
+ before do
152
150
  @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/LtC.png"
153
151
  ::FileUtils.mkdir_p("#{$tmp_alt_flags_dir}/PNG/")
154
152
  end
155
153
 
156
- it 'should not raise PNGGenerationError with png_file set' do
157
- expect { @flag.png }.to_not raise_error
154
+ it 'does not raise PNGGenerationError with png_file set' do
155
+ expect { @flag.png }.not_to raise_error
158
156
  end
159
157
 
160
- it 'should return the value of png_file' do
158
+ it 'returns the value of png_file' do
161
159
  expect(@flag.png).to eql("#{$tmp_alt_flags_dir}/PNG/LtC.png")
162
160
  end
163
161
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'usps_flags'
5
- s.version = '0.5.0'
5
+ s.version = '0.5.1'
6
6
  s.date = '2019-06-07'
7
7
  s.summary = 'Flag generator for United States Power Squadrons'
8
8
  s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
@@ -14,14 +14,15 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- spec/*`.split("\n")
16
16
 
17
- s.required_ruby_version = '~> 2.4'
17
+ s.required_ruby_version = '~> 2.5'
18
18
 
19
19
  s.add_runtime_dependency 'file_utils', '~> 1.1', '>= 1.1.2'
20
20
  s.add_runtime_dependency 'mini_magick', '~> 4.8', '>= 4.8.0'
21
21
  s.add_runtime_dependency 'rubyzip', '~> 1.2', '>= 1.2.1'
22
22
 
23
- s.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
24
- s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
25
- s.add_development_dependency 'rubocop', '~> 0.59', '>= 0.59.2'
26
- s.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
23
+ s.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
24
+ s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
25
+ s.add_development_dependency 'rubocop', '~> 0.71', '>= 0.71.0'
26
+ s.add_development_dependency 'rubocop-rspec', '~> 1.30', '>= 1.30.0'
27
+ s.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
27
28
  end
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -116,20 +116,40 @@ dependencies:
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: '0.59'
119
+ version: '0.71'
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: 0.59.2
122
+ version: 0.71.0
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '0.59'
129
+ version: '0.71'
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 0.59.2
132
+ version: 0.71.0
133
+ - !ruby/object:Gem::Dependency
134
+ name: rubocop-rspec
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.30'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 1.30.0
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '1.30'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.30.0
133
153
  - !ruby/object:Gem::Dependency
134
154
  name: simplecov
135
155
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +187,6 @@ files:
167
187
  - LICENSE
168
188
  - README.md
169
189
  - Rakefile
170
- - lib/rational.rb
171
190
  - lib/usps_flags.rb
172
191
  - lib/usps_flags/config.rb
173
192
  - lib/usps_flags/core.rb
@@ -190,8 +209,11 @@ files:
190
209
  - lib/usps_flags/core/trident_specs/circle.rb
191
210
  - lib/usps_flags/core/trident_specs/delta.rb
192
211
  - lib/usps_flags/core/trident_specs/header.rb
212
+ - lib/usps_flags/core/trident_specs/horizontal.rb
193
213
  - lib/usps_flags/core/trident_specs/long.rb
214
+ - lib/usps_flags/core/trident_specs/overlay.rb
194
215
  - lib/usps_flags/core/trident_specs/short.rb
216
+ - lib/usps_flags/core/trident_specs/vertical.rb
195
217
  - lib/usps_flags/core/tridents.rb
196
218
  - lib/usps_flags/core/us.rb
197
219
  - lib/usps_flags/core/us_defs.svg.partial
@@ -200,17 +222,19 @@ files:
200
222
  - lib/usps_flags/errors.rb
201
223
  - lib/usps_flags/generate.rb
202
224
  - lib/usps_flags/generate/flag.rb
203
- - lib/usps_flags/generate/private.rb
225
+ - lib/usps_flags/generate/generator_methods.rb
226
+ - lib/usps_flags/generate/helper_methods.rb
204
227
  - lib/usps_flags/helpers.rb
205
228
  - lib/usps_flags/helpers/builders.rb
206
229
  - lib/usps_flags/helpers/spec_arrows.rb
207
230
  - lib/usps_flags/helpers/valid_flags.rb
208
- - spec/rational_spec.rb
231
+ - lib/usps_flags/rational.rb
209
232
  - spec/spec_helper.rb
210
233
  - spec/usps_flags/config_spec.rb
211
234
  - spec/usps_flags/core_spec.rb
212
235
  - spec/usps_flags/generate_spec.rb
213
236
  - spec/usps_flags/helpers_spec.rb
237
+ - spec/usps_flags/rational_spec.rb
214
238
  - spec/usps_flags_spec.rb
215
239
  - usps_flags.gemspec
216
240
  homepage: http://rubygems.org/gems/usps_flags
@@ -227,7 +251,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
227
251
  requirements:
228
252
  - - "~>"
229
253
  - !ruby/object:Gem::Version
230
- version: '2.4'
254
+ version: '2.5'
231
255
  required_rubygems_version: !ruby/object:Gem::Requirement
232
256
  requirements:
233
257
  - - ">="
@@ -240,10 +264,10 @@ signing_key:
240
264
  specification_version: 4
241
265
  summary: Flag generator for United States Power Squadrons
242
266
  test_files:
243
- - spec/rational_spec.rb
244
267
  - spec/spec_helper.rb
245
268
  - spec/usps_flags/config_spec.rb
246
269
  - spec/usps_flags/core_spec.rb
247
270
  - spec/usps_flags/generate_spec.rb
248
271
  - spec/usps_flags/helpers_spec.rb
272
+ - spec/usps_flags/rational_spec.rb
249
273
  - spec/usps_flags_spec.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- # Monkey patch to add some formatting methods to Rational.
4
- #
5
- # @author Julian Fiander
6
- # @since 0.1.5
7
- class Rational
8
- # Converts Rational to String
9
- #
10
- # If Rational is an improper fraction, removes the integer part to convert to a mixed fraction.
11
- #
12
- # @example Mixed fraction
13
- # Rational(4,3).to_simplified_s #=> "1 1/3"
14
- # @return [String] If less than 1, fraction. If greater than 1, a mixed fraction.
15
- def to_simplified_s
16
- if self < 1
17
- to_s
18
- else
19
- truncated = self.truncate
20
- "#{truncated} #{self - truncated}"
21
- end
22
- end
23
-
24
- # Converts Rational to Array
25
- #
26
- # If Rational is an improper fraction, removes the integer part to convert to a mixed fraction.
27
- #
28
- # @example Mixed fraction
29
- # Rational(4,3).to_simplified_a #=> [1, Rational(1,3)]
30
- # @return [Array] If less than 1, fraction. If greater than 1, a mixed fraction.
31
- def to_simplified_a
32
- if self < 1
33
- to_s
34
- else
35
- truncated = self.truncate
36
- [truncated, (self - truncated)]
37
- end
38
- end
39
- end
@@ -1,199 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- # Private methods for USPSFlags::Generator.
4
- #
5
- # These methods should never need to be called directly.
6
- # @private
7
- module USPSFlags::Generate::Private
8
- private
9
-
10
- def any_all_arg?(svg, png, zips, reset)
11
- svg || png || zips || reset
12
- end
13
-
14
- def all_arg_error
15
- raise(
16
- USPSFlags::Errors::StaticFilesGenerationError,
17
- 'At least one argument switch must be true out of [svg, png, zips, reset].'
18
- )
19
- end
20
-
21
- def track_time(simple: false)
22
- overall_start_time = Time.now
23
- yield
24
- end_time = Time.now - overall_start_time
25
- simple ? end_time : USPSFlags::Helpers.log("\nTotal run time: #{end_time} s\n\n")
26
- end
27
-
28
- def remove_static_files
29
- ['SVG', 'PNG', 'ZIP'].each do |dir|
30
- dir_path = "#{USPSFlags.configuration.flags_dir}/#{dir}"
31
- ::FileUtils.rm_rf(::Dir.glob("#{dir_path}/*")) if ::Dir.exist?(dir_path)
32
- end
33
- ['SVG/insignia', 'PNG/insignia'].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags.configuration.flags_dir}/#{dir}") }
34
- USPSFlags::Helpers.log "\n - Cleared previous files.\n"
35
- end
36
-
37
- def set_file_paths
38
- @svg_file = "#{USPSFlags.configuration.flags_dir}/SVG/#{@flag}.svg"
39
- @png_file = @svg_file.gsub('/SVG/', '/PNG/').gsub('.svg', '.png')
40
- @svg_ins_file = @svg_file.gsub('/SVG/', '/SVG/insignia/')
41
- @png_ins_file = @svg_file.gsub('/SVG/', '/PNG/insignia/').gsub('.svg', '.png')
42
- [@svg_file, @png_file, @svg_ins_file, @png_ins_file]
43
- end
44
-
45
- def static_generation_header
46
- puts "\nSVGs generate a single file.",
47
- 'PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.',
48
- 'Corresponding rank insignia (including smaller sizes) are also generated, as appropriate.'
49
- USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags.configuration.flags_dir}\n"
50
- USPSFlags::Helpers.log "\n#{Time.now.strftime('%Y%m%d.%H%M%S%z')} – Generating static files...\n\n"
51
- USPSFlags::Helpers.log "Flag | SVG | PNG | Run time\n".rjust(USPSFlags::Helpers.max_flag_name_length + 31),
52
- "\n".rjust(USPSFlags::Helpers.max_flag_name_length + 32, '-')
53
- end
54
-
55
- def generate_zip(type)
56
- no_dir = [USPSFlags::Errors::ZipGenerationError, 'Flags directory not found.']
57
- raise *no_dir unless ::Dir.exist?("#{USPSFlags.configuration.flags_dir}/ZIP")
58
-
59
- zip = "#{USPSFlags.configuration.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
60
- ::File.delete(zip) if ::File.exist?(zip)
61
- write_zip_file(zip, type)
62
-
63
- puts "Generated #{type.upcase} Zip"
64
- end
65
-
66
- def write_zip_file(zip, type)
67
- ::Zip::File.open(zip, ::Zip::File::CREATE) do |z|
68
- ::Dir.glob("#{USPSFlags.configuration.flags_dir}/#{type.upcase}/**/*").each do |f|
69
- add_to_zip(z, f)
70
- end
71
- end
72
- end
73
-
74
- def add_to_zip(z, f)
75
- filename = f.split('/').last
76
- filename = "insignia/#{filename}" if f.split('/').last(2).first == 'insignia'
77
- z.add(filename, f)
78
- end
79
-
80
- def generate_static_images_for(flag, svg: true, png: true)
81
- run_time = track_time(simple: true) do
82
- @flag = flag.upcase
83
- USPSFlags::Helpers.log "#{@flag.rjust(USPSFlags::Helpers.max_flag_name_length)} |"
84
- set_file_paths
85
- generate_requested_images(svg, png)
86
- end
87
-
88
- USPSFlags::Helpers.log " | #{run_time.round(4).to_s[(0..5)].ljust(6, '0')} s\n"
89
- end
90
-
91
- def generate_requested_images(svg, png)
92
- svg ? generate_static_svg : USPSFlags::Helpers.log('-')
93
- png ? generate_static_png : USPSFlags::Helpers.log('- ')
94
- end
95
-
96
- def generate_static_svg
97
- USPSFlags::Helpers.log ' '
98
-
99
- generate_regular_svg
100
- generate_insignia_svg
101
- end
102
-
103
- def generate_regular_svg
104
- return if file_found?(@svg_file)
105
-
106
- svg @flag, outfile: @svg_file, scale: 1
107
- USPSFlags::Helpers.log 'S'
108
- end
109
-
110
- def generate_insignia_svg
111
- return if no_insignia?
112
-
113
- svg @flag, field: false, outfile: @svg_ins_file, scale: 1
114
- USPSFlags::Helpers.log 'I'
115
- end
116
-
117
- def set_temp_svg(svg)
118
- @temp_svg_path = "#{USPSFlags.configuration.flags_dir}/temp.svg"
119
- temp_svg = ::File.new(@temp_svg_path, 'w+')
120
- temp_svg.write(svg)
121
- temp_svg.flush
122
- @temp_svg_path
123
- end
124
-
125
- def delete_temp_svg?
126
- !@temp_svg_path.to_s.empty? && ::File.exist?(@temp_svg_path)
127
- end
128
-
129
- def generate_static_png
130
- USPSFlags::Helpers.log ' | '
131
- generate_fullsize_png
132
- generate_fullsize_png_insignia
133
- generate_reduced_size_pngs
134
- end
135
-
136
- def generate_fullsize_png
137
- return if file_found?(@png_file)
138
-
139
- png(File.read(@svg_file), outfile: @png_file)
140
- USPSFlags::Helpers.log 'F'
141
- end
142
-
143
- def generate_fullsize_png_insignia
144
- return if no_insignia?
145
- return if file_found?(@png_ins_file)
146
-
147
- png(File.read(@svg_ins_file), outfile: @png_ins_file, trim: true)
148
- USPSFlags::Helpers.log 'I'
149
- end
150
-
151
- def generate_reduced_size_pngs
152
- USPSFlags::Helpers.png_sizes.keys.each do |size|
153
- size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: @flag)
154
- @sized_png_file = "#{USPSFlags.configuration.flags_dir}/PNG/#{@flag}.#{size_key}.png"
155
- @sized_png_ins_file = @sized_png_file.gsub('/PNG/', '/PNG/insignia/')
156
-
157
- generate_smaller_png(size, size_key)
158
- generate_smaller_png_insignia(size, size_key)
159
- end
160
- end
161
-
162
- def generate_smaller_png(size, size_key)
163
- return if file_found?(@sized_png_file)
164
- return if too_big?(@png_file, size)
165
-
166
- USPSFlags::Helpers.resize_png(@png_file, file: @flag, size: size, size_key: size_key)
167
- USPSFlags::Helpers.log USPSFlags::Helpers.png_sizes[size_key]
168
- end
169
-
170
- def generate_smaller_png_insignia(size, size_key)
171
- return if no_insignia?
172
- return if file_found?(@sized_png_ins_file)
173
- return if too_big?(@png_ins_file, size)
174
-
175
- USPSFlags::Helpers.resize_png(@png_ins_file, file: "insignia/#{@flag}", size: size, size_key: size_key)
176
- USPSFlags::Helpers.log 'i'
177
- end
178
-
179
- def no_insignia?
180
- return false if USPSFlags::Helpers.valid_flags(:insignia).include?(@flag)
181
-
182
- USPSFlags::Helpers.log '-'
183
- true
184
- end
185
-
186
- def file_found?(file)
187
- return false unless ::File.exist?(file)
188
-
189
- USPSFlags::Helpers.log '.'
190
- true
191
- end
192
-
193
- def too_big?(file, size)
194
- return false unless size > MiniMagick::Image.open(file)[:width]
195
-
196
- USPSFlags::Helpers.log '+'
197
- true
198
- end
199
- end