usps_flags-grades 0.0.12 → 0.1.0

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
  SHA256:
3
- metadata.gz: 5f9ab5d165c202f4af2a99caa777e90a0f5df7a4b06fd8de58fa9d3d3a86079d
4
- data.tar.gz: 5a54878338bdb11837dafa04550092da604b4f86ebdd5ae68a08410597f32c20
3
+ metadata.gz: 6bdf433909bdb2c4c11b00b4aa664f5ace40214bdb13f92445a81547c3564496
4
+ data.tar.gz: 1041c303c386e7fc4544f8f2697b1b58ef03be34dd8893f744b23a14fd7808cb
5
5
  SHA512:
6
- metadata.gz: b7b2a9a9438a142a22991c594c9c36c11859cb4066f3f0995bcc31a2e9f5693b1298298b06fc72faf45135421cbb54fa3b37d081d356fc596d3c31e246877e0a
7
- data.tar.gz: 1e210586ed6693d2708e17ca7dee3026de42e5afd9db08a0ef174957ba5a9d28dc61fdd65e039aecd19dcce09f82500f34b4a44fa5a3460ba229e477daace60b
6
+ metadata.gz: 37e5322d5e65fc660a997ae4d285a74209e449aacaae2a2932e2147bd3ec0144269b6c60d06f92880ea51e758612caaa463427df0c202c8748d514b6ac289fe5
7
+ data.tar.gz: f085c2a13816ca03bcba479121170fa995e0c6432193d456c5d8104b894eb1a5c37aac59c83dafbeea52d8582c540d5268eef7dab4b8791688dcdb392ec705bb
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags-grades (0.0.12)
5
- usps_flags (~> 0.4, >= 0.4.0)
4
+ usps_flags-grades (0.1.0)
5
+ usps_flags (~> 0.5, >= 0.5.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -32,7 +32,7 @@ GEM
32
32
  json (>= 1.8, < 3)
33
33
  simplecov-html (~> 0.10.0)
34
34
  simplecov-html (0.10.2)
35
- usps_flags (0.4.1)
35
+ usps_flags (0.5.1)
36
36
  file_utils (~> 1.1, >= 1.1.2)
37
37
  mini_magick (~> 4.8, >= 4.8.0)
38
38
  rubyzip (~> 1.2, >= 1.2.1)
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new
5
7
 
6
8
  task default: :spec
7
- task test: :spec
9
+ task test: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'usps_flags'
2
4
  require 'usps_flags/grades/config'
3
5
  require 'usps_flags/grades/errors'
@@ -27,12 +29,12 @@ class USPSFlags::Grades
27
29
  #
28
30
  # insignia.svg #=> Generates SVG file at "/path/to/svg/output.svg"
29
31
  def initialize(options = {})
30
- @grade = options[:grade] || nil
32
+ @grade = options[:grade]
31
33
  @edpro = options[:edpro] || false
32
- @membership = options[:membership] || nil
34
+ @membership = options[:membership]
33
35
  @merit_marks = options[:merit_marks] || 0
34
- @outfile = options[:outfile] || nil
35
- @generated_at = Time.now.strftime("%Y%m%d.%H%S%z")
36
+ @outfile = options[:outfile]
37
+ @generated_at = Time.now.strftime('%Y%m%d.%H%S%z')
36
38
  yield self if block_given?
37
39
  end
38
40
 
@@ -68,12 +70,12 @@ class USPSFlags::Grades
68
70
  # @return [String] Returns the descriptive title.
69
71
  def title
70
72
  grade = @grade.to_s.upcase
71
- edpro = " - EdPro" if @edpro && @grade != :sn
73
+ edpro = ' - EdPro' if @edpro && @grade != :sn
72
74
  membership = case @membership
73
- when :senior
74
- " - Senior Member"
75
- when :life
76
- " - Life Member"
75
+ when :senior
76
+ ' - Senior Member'
77
+ when :life
78
+ ' - Life Member'
77
79
  end
78
80
 
79
81
  "#{grade}#{edpro}#{membership}"
@@ -95,7 +97,7 @@ class USPSFlags::Grades
95
97
  end
96
98
  end
97
99
 
98
- private
100
+ private
99
101
 
100
102
  def validate
101
103
  validate_grade
@@ -112,7 +114,7 @@ class USPSFlags::Grades
112
114
  def validate_edpro
113
115
  return if [true, false].include?(@edpro)
114
116
 
115
- raise USPSFlags::Errors::InvalidInsignia, "EdPro must be boolean"
117
+ raise USPSFlags::Errors::InvalidInsignia, 'EdPro must be boolean'
116
118
  end
117
119
 
118
120
  def validate_membership
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Extension of USPSFlags::Config to for insignia config.
2
4
  #
3
5
  # @private
4
6
  class USPSFlags::Config
5
- GOLD ||= "#FFBF3F"
7
+ GOLD ||= '#FFBF3F'
6
8
  GRADE_SPACING ||= 125
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Core SVG data for the Educational Proficiency insignia.
2
4
  #
3
5
  # This class should never need to be called directly.
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Custom errors.
2
4
  #
3
5
  # @private
4
- module USPSFlags::Errors
5
- class USPSFlags::Errors::InvalidInsignia < StandardError
6
- def initialize(msg = "You have specified invalid insignia.")
7
- super(msg)
6
+ class USPSFlags
7
+ class Errors
8
+ class InvalidInsignia < StandardError
9
+ def initialize(msg = 'You have specified invalid insignia.')
10
+ super(msg)
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Core SVG data for grade insignia.
2
4
  #
3
5
  # This class should never need to be called directly.
@@ -26,7 +28,7 @@ class USPSFlags::Grades::Grade
26
28
  end
27
29
  end
28
30
 
29
- private
31
+ private
30
32
 
31
33
  def bar
32
34
  <<~SVG
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Core SVG data for the membership level insignia.
2
4
  #
3
5
  # This class should never need to be called directly.
@@ -11,7 +13,7 @@ class USPSFlags::Grades::Membership
11
13
  SVG
12
14
  end
13
15
 
14
- private
16
+ private
15
17
 
16
18
  def arrow
17
19
  <<~SVG
@@ -1,3 +1,5 @@
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.
@@ -7,27 +9,32 @@ class USPSFlags::Grades::MeritMarks
7
9
  def get(number)
8
10
  return if number < 1
9
11
 
10
- svg = ""
12
+ svg = +''
11
13
  new_lines = 0
12
14
 
13
15
  top_row = number % 20
14
16
  svg << generate_top_row(top_row)
15
17
  number -= top_row
16
18
 
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>" }
19
+ number, new_lines, svg = add_row(number, new_lines, svg) while number > 0
20
+ new_lines.times { svg << '</g>' }
26
21
 
27
22
  svg
28
23
  end
29
24
 
30
- private
25
+ private
26
+
27
+ def add_row(number, new_lines, svg)
28
+ number -= 20
29
+ new_lines += 1
30
+ svg << <<~SVG
31
+ <g transform="translate(0,90)">
32
+ #{generate_full_row}
33
+ SVG
34
+
35
+ [number, new_lines, svg]
36
+ end
37
+
31
38
  def bar(offset = 0)
32
39
  <<~SVG
33
40
  <rect x="#{offset}" y="0" width="35" height="80" fill="#{USPSFlags::Config::GOLD}" />
@@ -35,7 +42,7 @@ class USPSFlags::Grades::MeritMarks
35
42
  end
36
43
 
37
44
  def generate_top_row(number)
38
- svg = ""
45
+ svg = +''
39
46
 
40
47
  number.times do |i|
41
48
  svg << bar(45 * i)
@@ -45,7 +52,7 @@ class USPSFlags::Grades::MeritMarks
45
52
  end
46
53
 
47
54
  def generate_full_row
48
- svg = ""
55
+ svg = +''
49
56
 
50
57
  20.times do |i|
51
58
  svg << bar(45 * i)
data/spec/spec_helper.rb CHANGED
@@ -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
+ describe 'invalid insignia' do
7
+ it 'should raise USPSFlags::Errors::InvalidInsignia if an invalid grade is specified' do
6
8
  @insignia = USPSFlags::Grades.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
18
+ it 'should raise USPSFlags::Errors::InvalidInsignia if an invalid edpro is specified' do
17
19
  @insignia = USPSFlags::Grades.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
29
+ it 'should raise USPSFlags::Errors::InvalidInsignia if an invalid membership is specified' do
28
30
  @insignia = USPSFlags::Grades.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
41
+ context 'S' do
40
42
  before(:each) do
41
43
  @insignia = USPSFlags::Grades.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 'should have 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
59
+ context 'P' do
58
60
  before(:each) do
59
61
  @insignia = USPSFlags::Grades.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 'should have 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
80
+ context 'AP - EdPro' do
79
81
  before(:each) do
80
82
  @insignia = USPSFlags::Grades.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 'should have 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 'should have 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
126
+ context 'JN - 5MM' do
125
127
  before(:each) do
126
128
  @insignia = USPSFlags::Grades.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 'should have 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 'should have 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 'should not have a 6th position merit mark' do
185
+ expect(@insignia.svg).to_not 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 'should have 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
197
+ context 'N - Life Member' do
196
198
  before(:each) do
197
199
  @insignia = USPSFlags::Grades.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 'should have the N insignia' do
205
207
  expect(@insignia.svg).to include(
206
208
  <<~SVG
207
209
  <g transform="translate(0, 50)">
@@ -263,29 +265,31 @@ describe USPSFlags::Grades do
263
265
  )
264
266
  end
265
267
 
266
- it "should have a life member arrow" do
268
+ it 'should have 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
277
+ context 'SN - Senior Member - 20 MM' do
274
278
  before(:each) do
275
279
  @insignia = USPSFlags::Grades.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
287
+ it 'should have the SN insignia box' do
284
288
  expect(@insignia.svg).to include('<rect x="20" y="-10" width="')
285
289
  expect(@insignia.svg).to include('" height="155" fill="none" stroke-width="20"')
286
290
  end
287
291
 
288
- it "should have a senior member arrow" do
292
+ it 'should have a senior member arrow' do
289
293
  expect(@insignia.svg).to include(
290
294
  <<~SVG
291
295
  <polyline points="0,250 75,220 75,240 150,240 150,260 75,260 75,280 0,250" fill="#FFBF3F" />
@@ -299,12 +303,18 @@ describe USPSFlags::Grades do
299
303
  )
300
304
  end
301
305
 
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\" />")
306
+ it 'should have a 20th position merit mark' do
307
+ expect(@insignia.svg).to include('<rect x="855" y="0" width="35" height="80" fill="#FFBF3F" />')
304
308
  end
305
309
  end
306
310
 
307
311
  it 'should generate all without error' do
308
312
  expect(USPSFlags::Grades.all).to eql(USPSFlags::Grades::ALL_CONFIGS)
309
313
  end
314
+
315
+ it 'should raise the correct error with an invalid edpro request' do
316
+ expect { USPSFlags::Grades::EdPro.get(:s) }.to raise_error(
317
+ USPSFlags::Errors::InvalidInsignia, 'EdPro is only valid for grades AP, JN, N'
318
+ )
319
+ end
310
320
  end
@@ -1,7 +1,9 @@
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.0'
6
+ s.date = '2019-06-08'
5
7
  s.summary = 'Insignia generator for United States Power Squadrons'
6
8
  s.description = 'An extension to the flag image (PNG, SVG) generator for United States Power Squadrons to generate grade insignia.'
7
9
  s.homepage = 'http://rubygems.org/gems/usps_flags-grades'
@@ -14,7 +16,7 @@ Gem::Specification.new do |s|
14
16
 
15
17
  s.required_ruby_version = '~> 2.4'
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.1'
18
20
 
19
21
  s.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
20
22
  s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
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.0
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: 2019-06-08 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.1
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.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement