usps_flags-grades 0.0.12 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,57 +1,60 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Core SVG data for merit marks.
2
4
  #
3
5
  # This class should never need to be called directly.
4
6
  # @private
5
- class USPSFlags::Grades::MeritMarks
6
- class << self
7
- def get(number)
8
- return if number < 1
9
-
10
- svg = ""
11
- new_lines = 0
12
-
13
- top_row = number % 20
14
- svg << generate_top_row(top_row)
15
- number -= top_row
16
-
17
- while number > 0
18
- number -= 20
19
- new_lines += 1
20
- svg << <<~SVG
21
- <g transform="translate(0,90)">
22
- #{generate_full_row}
23
- SVG
24
- end
25
- new_lines.times { svg << "</g>" }
26
-
27
- svg
28
- end
29
-
30
- private
31
- def bar(offset = 0)
32
- <<~SVG
33
- <rect x="#{offset}" y="0" width="35" height="80" fill="#{USPSFlags::Config::GOLD}" />
34
- SVG
35
- end
36
-
37
- def generate_top_row(number)
38
- svg = ""
39
-
40
- number.times do |i|
41
- svg << bar(45 * i)
7
+ class USPSFlags
8
+ class Grades
9
+ class MeritMarks
10
+ class << self
11
+ def get(number)
12
+ return if number < 1
13
+
14
+ svg = +''
15
+ new_lines = 0
16
+
17
+ top_row = number % 20
18
+ svg << generate_top_row(top_row)
19
+ number -= top_row
20
+
21
+ number, new_lines, svg = add_row(number, new_lines, svg) while number.positive?
22
+ new_lines.times { svg << '</g>' }
23
+
24
+ svg
25
+ end
26
+
27
+ private
28
+
29
+ def add_row(number, new_lines, svg)
30
+ number -= 20
31
+ new_lines += 1
32
+ svg << <<~SVG
33
+ <g transform="translate(0,90)">
34
+ #{generate_full_row}
35
+ SVG
36
+
37
+ [number, new_lines, svg]
38
+ end
39
+
40
+ def bar(offset = 0)
41
+ <<~SVG
42
+ <rect x="#{offset}" y="0" width="35" height="80" fill="#{USPSFlags::Config::GOLD}" />
43
+ SVG
44
+ end
45
+
46
+ def generate_top_row(number)
47
+ svg = +''
48
+ number.times { |i| svg << bar(45 * i) }
49
+ svg
50
+ end
51
+
52
+ def generate_full_row
53
+ svg = +''
54
+ 20.times { |i| svg << bar(45 * i) }
55
+ svg
56
+ end
42
57
  end
43
-
44
- svg
45
- end
46
-
47
- def generate_full_row
48
- svg = ""
49
-
50
- 20.times do |i|
51
- svg << bar(45 * i)
52
- end
53
-
54
- svg
55
58
  end
56
59
  end
57
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  Bundler.setup
3
5
  require 'simplecov'
@@ -12,7 +14,7 @@ RSpec::Expectations.configuration.on_potential_false_positives = :nothing
12
14
 
13
15
  RSpec.configure do |config|
14
16
  config.before(:suite) do
15
- $tmp_flags_dir = "tmp/flags"
17
+ $tmp_flags_dir = 'tmp/flags'
16
18
 
17
19
  USPSFlags.configure do |c|
18
20
  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("tmp") if ::Dir.exist?("tmp")
25
+ ::FileUtils.rm_rf('tmp') if ::Dir.exist?('tmp')
24
26
  end
25
27
  end
@@ -1,50 +1,52 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe USPSFlags::Grades do
4
- describe "invalid insignia" do
5
- it "should raise USPSFlags::Errors::InvalidInsignia if an invalid grade is specified" do
6
- @insignia = USPSFlags::Grades.new do |b|
6
+ describe 'invalid insignia' do
7
+ it 'raises USPSFlags::Errors::InvalidInsignia if an invalid grade is specified' do
8
+ @insignia = described_class.new do |b|
7
9
  b.grade = :not_a_grade
8
- b.outfile = ""
10
+ b.outfile = ''
9
11
  end
10
12
 
11
13
  expect { @insignia.svg }.to raise_error(
12
- USPSFlags::Errors::InvalidInsignia, "Unknown grade: not_a_grade"
14
+ USPSFlags::Errors::InvalidInsignia, 'Unknown grade: not_a_grade'
13
15
  )
14
16
  end
15
17
 
16
- it "should raise USPSFlags::Errors::InvalidInsignia if an invalid edpro is specified" do
17
- @insignia = USPSFlags::Grades.new do |b|
18
+ it 'raises USPSFlags::Errors::InvalidInsignia if an invalid edpro is specified' do
19
+ @insignia = described_class.new do |b|
18
20
  b.edpro = nil
19
- b.outfile = ""
21
+ b.outfile = ''
20
22
  end
21
23
 
22
24
  expect { @insignia.svg }.to raise_error(
23
- USPSFlags::Errors::InvalidInsignia, "EdPro must be boolean"
25
+ USPSFlags::Errors::InvalidInsignia, 'EdPro must be boolean'
24
26
  )
25
27
  end
26
28
 
27
- it "should raise USPSFlags::Errors::InvalidInsignia if an invalid membership is specified" do
28
- @insignia = USPSFlags::Grades.new do |b|
29
+ it 'raises USPSFlags::Errors::InvalidInsignia if an invalid membership is specified' do
30
+ @insignia = described_class.new do |b|
29
31
  b.membership = :normal
30
- b.outfile = ""
32
+ b.outfile = ''
31
33
  end
32
34
 
33
35
  expect { @insignia.svg }.to raise_error(
34
- USPSFlags::Errors::InvalidInsignia, "Unknown membership level: normal"
36
+ USPSFlags::Errors::InvalidInsignia, 'Unknown membership level: normal'
35
37
  )
36
38
  end
37
39
  end
38
40
 
39
- context "S" do
40
- before(:each) do
41
- @insignia = USPSFlags::Grades.new do |g|
41
+ context 'with S' do
42
+ before do
43
+ @insignia = described_class.new do |g|
42
44
  g.grade = :s
43
- g.outfile = ""
45
+ g.outfile = ''
44
46
  end
45
47
  end
46
48
 
47
- it "should have the S insignia" do
49
+ it 'has the S insignia' do
48
50
  expect(@insignia.svg).to include(
49
51
  <<~SVG
50
52
  <g transform="translate(0, 50)">
@@ -54,15 +56,15 @@ describe USPSFlags::Grades do
54
56
  end
55
57
  end
56
58
 
57
- context "P" do
58
- before(:each) do
59
- @insignia = USPSFlags::Grades.new do |g|
59
+ context 'with P' do
60
+ before do
61
+ @insignia = described_class.new do |g|
60
62
  g.grade = :p
61
- g.outfile = ""
63
+ g.outfile = ''
62
64
  end
63
65
  end
64
66
 
65
- it "should have the P insignia" do
67
+ it 'has the P insignia' do
66
68
  expect(@insignia.svg).to include(
67
69
  <<~SVG
68
70
  <g transform="translate(0, 50)">
@@ -75,16 +77,16 @@ describe USPSFlags::Grades do
75
77
  end
76
78
  end
77
79
 
78
- context "AP - EdPro" do
79
- before(:each) do
80
- @insignia = USPSFlags::Grades.new do |g|
80
+ context 'with AP - EdPro' do
81
+ before do
82
+ @insignia = described_class.new do |g|
81
83
  g.grade = :ap
82
84
  g.edpro = true
83
- g.outfile = ""
85
+ g.outfile = ''
84
86
  end
85
87
  end
86
88
 
87
- it "should have the AP insignia" do
89
+ it 'has the AP insignia' do
88
90
  expect(@insignia.svg).to include(
89
91
  <<~SVG
90
92
  <g transform="translate(0, 50)">
@@ -112,26 +114,26 @@ describe USPSFlags::Grades do
112
114
  )
113
115
  end
114
116
 
115
- it "should have the AP EdPro bar" do
117
+ it 'has the AP EdPro bar' do
116
118
  expect(@insignia.svg).to include(
117
119
  <<~SVG
118
- <rect x="0" y="100" width="381.25" height="15" fill="#FFBF3F" />
120
+ <rect x="0" y="100" width="381.25" height="20" fill="#FFBF3F" />
119
121
  SVG
120
122
  )
121
123
  end
122
124
  end
123
125
 
124
- context "JN - 5MM" do
125
- before(:each) do
126
- @insignia = USPSFlags::Grades.new do |g|
126
+ context 'with JN - 5MM' do
127
+ before do
128
+ @insignia = described_class.new do |g|
127
129
  g.grade = :jn
128
130
  g.merit_marks = 5
129
131
  g.edpro = true
130
- g.outfile = ""
132
+ g.outfile = ''
131
133
  end
132
134
  end
133
135
 
134
- it "should have the JN insignia" do
136
+ it 'has the JN insignia' do
135
137
  expect(@insignia.svg).to include(
136
138
  <<~SVG
137
139
  <g transform="translate(0, 50)">
@@ -175,33 +177,33 @@ describe USPSFlags::Grades do
175
177
  )
176
178
  end
177
179
 
178
- it "should have a 5th position merit mark" do
179
- expect(@insignia.svg).to include("<rect x=\"180\" y=\"0\" width=\"35\" height=\"80\" fill=\"#FFBF3F\" />")
180
+ it 'has a 5th position merit mark' do
181
+ expect(@insignia.svg).to include('<rect x="180" y="0" width="35" height="80" fill="#FFBF3F" />')
180
182
  end
181
183
 
182
- it "should not have a 6th position merit mark" do
183
- expect(@insignia.svg).to_not include("<rect x=\"225\" y=\"0\" width=\"35\" height=\"80\" fill=\"#FFBF3F\" />")
184
+ it 'does not have a 6th position merit mark' do
185
+ expect(@insignia.svg).not_to include('<rect x="225" y="0" width="35" height="80" fill="#FFBF3F" />')
184
186
  end
185
187
 
186
- it "should have the JN EdPro bar" do
188
+ it 'has the JN EdPro bar' do
187
189
  expect(@insignia.svg).to include(
188
190
  <<~SVG
189
- <rect x="0" y="100" width="385" height="15" fill="#FFBF3F" />
191
+ <rect x="0" y="100" width="385" height="20" fill="#FFBF3F" />
190
192
  SVG
191
193
  )
192
194
  end
193
195
  end
194
196
 
195
- context "N - Life Member" do
196
- before(:each) do
197
- @insignia = USPSFlags::Grades.new do |g|
197
+ context 'with N - Life Member' do
198
+ before do
199
+ @insignia = described_class.new do |g|
198
200
  g.grade = :n
199
201
  g.membership = :life
200
- g.outfile = ""
202
+ g.outfile = ''
201
203
  end
202
204
  end
203
205
 
204
- it "should have the N insignia" do
206
+ it 'has the N insignia' do
205
207
  expect(@insignia.svg).to include(
206
208
  <<~SVG
207
209
  <g transform="translate(0, 50)">
@@ -263,29 +265,32 @@ describe USPSFlags::Grades do
263
265
  )
264
266
  end
265
267
 
266
- it "should have a life member arrow" do
268
+ it 'has a life member arrow' do
267
269
  expect(@insignia.svg).to include(
268
- "m 107.6,178.2 c -0.2,0.7 -1.2,4.7 -2.1,8.8 -0.9,4.1 -2.2,9.7 -3,12.5 -7.9,29.7 -8.9,51.9 -2.9,67.7 4.5,12.2 7,16.7 8.9,16.7 2.4,0.1 12.2,-15.8 16.2,-26.4 6.4,-16.5 6.7,-18 6.7,-33.6 0.1,-15.7 -0.1,-16.4 -6.7,-29.7 -2,-3.9 -5.4,-8.5 -8.9,-11.8 -5.7,-5.5 -7.6,-6.4 -8.2,-4.2 z"
270
+ 'm 107.6,178.2 c -0.2,0.7 -1.2,4.7 -2.1,8.8 -0.9,4.1 -2.2,9.7 -3,12.5 -7.9,29.7 -8.9,51.9 -2.9,67.7 4.5,' \
271
+ '12.2 7,16.7 8.9,16.7 2.4,0.1 12.2,-15.8 16.2,-26.4 6.4,-16.5 6.7,-18 6.7,-33.6 0.1,-15.7 -0.1,-16.4 -6.7,' \
272
+ '-29.7 -2,-3.9 -5.4,-8.5 -8.9,-11.8 -5.7,-5.5 -7.6,-6.4 -8.2,-4.2 z'
269
273
  )
270
274
  end
271
275
  end
272
276
 
273
- context "SN - Senior Member - 20 MM" do
274
- before(:each) do
275
- @insignia = USPSFlags::Grades.new do |g|
277
+ context 'with SN - Senior Member - 20 MM' do
278
+ before do
279
+ @insignia = described_class.new do |g|
276
280
  g.grade = :sn
277
281
  g.membership = :senior
278
282
  g.merit_marks = 20
279
- g.outfile = ""
283
+ g.outfile = ''
280
284
  end
281
285
  end
282
286
 
283
- it "should have the SN insignia box" do
284
- expect(@insignia.svg).to include('<rect x="20" y="-10" width="')
285
- expect(@insignia.svg).to include('" height="155" fill="none" stroke-width="20"')
287
+ it 'has the SN insignia box' do
288
+ expect(@insignia.svg).to include(
289
+ '<rect x="20" y="-10" width="730" height="155" fill="none" stroke-width="20"'
290
+ )
286
291
  end
287
292
 
288
- it "should have a senior member arrow" do
293
+ it 'has a senior member arrow' do
289
294
  expect(@insignia.svg).to include(
290
295
  <<~SVG
291
296
  <polyline points="0,250 75,220 75,240 150,240 150,260 75,260 75,280 0,250" fill="#FFBF3F" />
@@ -299,12 +304,24 @@ describe USPSFlags::Grades do
299
304
  )
300
305
  end
301
306
 
302
- it "should have a 20th position merit mark" do
303
- expect(@insignia.svg).to include("<rect x=\"855\" y=\"0\" width=\"35\" height=\"80\" fill=\"#FFBF3F\" />")
307
+ it 'has a 20th position merit mark' do
308
+ expect(@insignia.svg).to include('<rect x="855" y="0" width="35" height="80" fill="#FFBF3F" />')
304
309
  end
305
310
  end
306
311
 
307
- it 'should generate all without error' do
308
- expect(USPSFlags::Grades.all).to eql(USPSFlags::Grades::ALL_CONFIGS)
312
+ it 'generates all without error' do
313
+ expect(described_class.all).to eql(USPSFlags::Grades::ALL_CONFIGS)
314
+ end
315
+
316
+ it 'raises the correct error with an invalid edpro request' do
317
+ expect { USPSFlags::Grades::EdPro.get(:s) }.to raise_error(
318
+ USPSFlags::Errors::InvalidInsignia, 'EdPro is only valid for grades AP, JN, N'
319
+ )
320
+ end
321
+
322
+ it 'does not raise an error from png' do
323
+ expect { described_class.new { |g| g.membership = :life }.png(outfile: './life.png') }.not_to(raise_error)
324
+ ensure
325
+ File.delete('./life.png')
309
326
  end
310
327
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'usps_flags-grades'
3
- s.version = '0.0.12'
4
- s.date = '2019-06-04'
5
+ s.version = '0.1.5'
6
+ s.date = '2020-08-03'
5
7
  s.summary = 'Insignia generator for United States Power Squadrons'
6
- s.description = 'An extension to the flag image (PNG, SVG) generator for United States Power Squadrons to generate grade insignia.'
8
+ s.description = 'An extension to the flag image generator for United States Power Squadrons to generate insignia.'
7
9
  s.homepage = 'http://rubygems.org/gems/usps_flags-grades'
8
10
  s.license = 'GPL-3.0'
9
11
  s.authors = ['Julian Fiander']
@@ -12,11 +14,13 @@ Gem::Specification.new do |s|
12
14
  s.files = `git ls-files`.split("\n")
13
15
  s.test_files = `git ls-files -- spec/*`.split("\n")
14
16
 
15
- s.required_ruby_version = '~> 2.4'
17
+ s.required_ruby_version = '~> 2.5'
16
18
 
17
- s.add_runtime_dependency 'usps_flags', '~> 0.4', '>= 0.4.0'
19
+ s.add_runtime_dependency 'usps_flags', '~> 0.5', '>= 0.5.5'
18
20
 
19
- s.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
20
- s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
21
- s.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
21
+ s.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
22
+ s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
23
+ s.add_development_dependency 'rubocop', '~> 0.71', '>= 0.71.0'
24
+ s.add_development_dependency 'rubocop-rspec', '~> 1.30', '>= 1.30.0'
25
+ s.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
22
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps_flags-grades
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-04 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: usps_flags
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0.5'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.4.0
22
+ version: 0.5.5
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.4'
29
+ version: '0.5'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.4.0
32
+ version: 0.5.5
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +70,46 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 3.7.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: rubocop
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.71'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.71.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.71'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.71.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: rubocop-rspec
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.30'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 1.30.0
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.30'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 1.30.0
73
113
  - !ruby/object:Gem::Dependency
74
114
  name: simplecov
75
115
  requirement: !ruby/object:Gem::Requirement
@@ -90,8 +130,8 @@ dependencies:
90
130
  - - ">="
91
131
  - !ruby/object:Gem::Version
92
132
  version: 0.15.1
93
- description: An extension to the flag image (PNG, SVG) generator for United States
94
- Power Squadrons to generate grade insignia.
133
+ description: An extension to the flag image generator for United States Power Squadrons
134
+ to generate insignia.
95
135
  email: julian@fiander.one
96
136
  executables: []
97
137
  extensions: []
@@ -99,6 +139,8 @@ extra_rdoc_files: []
99
139
  files:
100
140
  - ".gitignore"
101
141
  - ".rspec"
142
+ - ".rubocop.yml"
143
+ - ".ruby-version"
102
144
  - ".travis.yml"
103
145
  - ".yardopts"
104
146
  - CONTRIBUTING.md
@@ -130,15 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
172
  requirements:
131
173
  - - "~>"
132
174
  - !ruby/object:Gem::Version
133
- version: '2.4'
175
+ version: '2.5'
134
176
  required_rubygems_version: !ruby/object:Gem::Requirement
135
177
  requirements:
136
178
  - - ">="
137
179
  - !ruby/object:Gem::Version
138
180
  version: '0'
139
181
  requirements: []
140
- rubyforge_project:
141
- rubygems_version: 2.7.6
182
+ rubygems_version: 3.1.4
142
183
  signing_key:
143
184
  specification_version: 4
144
185
  summary: Insignia generator for United States Power Squadrons