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.
- checksums.yaml +4 -4
- data/.rubocop.yml +95 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -1
- data/Gemfile +3 -1
- data/Gemfile.lock +28 -9
- data/README.md +1 -1
- data/Rakefile +5 -3
- data/lib/usps_flags/grades.rb +110 -98
- data/lib/usps_flags/grades/config.rb +7 -3
- data/lib/usps_flags/grades/edpro.rb +16 -12
- data/lib/usps_flags/grades/errors.rb +8 -4
- data/lib/usps_flags/grades/grade.rb +83 -77
- data/lib/usps_flags/grades/membership.rb +130 -124
- data/lib/usps_flags/grades/merit_marks.rb +52 -49
- data/spec/spec_helper.rb +4 -2
- data/spec/usps_flags/grades_spec.rb +77 -60
- data/usps_flags-grades.gemspec +12 -8
- metadata +52 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cefac45cc5531db3f4f992a90e1b527a7e743aaf982a6266d6b6fb30d2256e17
|
4
|
+
data.tar.gz: 732876a050800e686568512f63274b38ad6a296ceab6f0b777bb4085b6de07a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db74e2ca7a56c73a99f1cdc90bbaaade93598c7c44fd662af77c0586d98c58a93c19cf41bb802a1f8225e5610d03df24f78e95e922c909a328e41521b0620bdc
|
7
|
+
data.tar.gz: b70066bc684b2c02de5b54c010955b3a9cc1efdcb32b85e44c9fa83a928a39e1989ec1b661370680425bfed860c60bf0cf76bc37cbd5d5e848f6b6523bc29a3a
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
AllCops:
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
Exclude:
|
5
|
+
- lib/output/*
|
6
|
+
- tmp/**/*
|
7
|
+
- vendor/**/*
|
8
|
+
|
9
|
+
Layout/IndentFirstHashElement:
|
10
|
+
EnforcedStyle: consistent
|
11
|
+
Layout/AccessModifierIndentation:
|
12
|
+
EnforcedStyle: outdent
|
13
|
+
Layout/EmptyLinesAroundAccessModifier:
|
14
|
+
Enabled: true
|
15
|
+
Layout/AlignArray:
|
16
|
+
Enabled: true
|
17
|
+
Layout/AlignHash:
|
18
|
+
Enabled: true
|
19
|
+
Layout/EmptyLineAfterGuardClause:
|
20
|
+
Enabled: true
|
21
|
+
Layout/SpaceInsideBlockBraces:
|
22
|
+
EnforcedStyle: space
|
23
|
+
EnforcedStyleForEmptyBraces: no_space
|
24
|
+
Layout/SpaceInsideHashLiteralBraces:
|
25
|
+
EnforcedStyle: space
|
26
|
+
EnforcedStyleForEmptyBraces: no_space
|
27
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
28
|
+
EnforcedStyle: no_space
|
29
|
+
Layout/EndAlignment:
|
30
|
+
EnforcedStyleAlignWith: start_of_line
|
31
|
+
|
32
|
+
Lint/UnusedMethodArgument:
|
33
|
+
Enabled: true
|
34
|
+
Lint/UselessAssignment:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Metrics/BlockLength:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*.rb'
|
40
|
+
Metrics/LineLength:
|
41
|
+
Max: 120
|
42
|
+
Metrics/MethodLength:
|
43
|
+
Enabled: true
|
44
|
+
Metrics/ClassLength:
|
45
|
+
Enabled: true
|
46
|
+
Max: 125
|
47
|
+
Metrics/ParameterLists:
|
48
|
+
Enabled: true
|
49
|
+
Metrics/CyclomaticComplexity:
|
50
|
+
Enabled: true
|
51
|
+
Metrics/AbcSize:
|
52
|
+
Enabled: true
|
53
|
+
|
54
|
+
Naming/UncommunicativeMethodParamName:
|
55
|
+
Enabled: false
|
56
|
+
Naming/AccessorMethodName:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
RSpec/MessageSpies:
|
60
|
+
EnforcedStyle: receive
|
61
|
+
RSpec/InstanceVariable:
|
62
|
+
Enabled: false
|
63
|
+
RSpec/NestedGroups:
|
64
|
+
Enabled: false
|
65
|
+
RSpec/ExampleLength:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Style/Documentation:
|
69
|
+
Enabled: false
|
70
|
+
Style/FrozenStringLiteralComment:
|
71
|
+
Enabled: true
|
72
|
+
Style/NumericLiterals:
|
73
|
+
Enabled: true
|
74
|
+
Style/StringLiterals:
|
75
|
+
EnforcedStyle: single_quotes
|
76
|
+
Style/AndOr:
|
77
|
+
Enabled: true
|
78
|
+
Style/ClassCheck:
|
79
|
+
Enabled: true
|
80
|
+
Style/GuardClause:
|
81
|
+
Enabled: true
|
82
|
+
Style/ClassAndModuleChildren:
|
83
|
+
EnforcedStyle: nested
|
84
|
+
Style/GlobalVars:
|
85
|
+
Exclude:
|
86
|
+
- 'spec/**/*.rb'
|
87
|
+
Style/ParallelAssignment:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
Security/Eval:
|
91
|
+
Enabled: true
|
92
|
+
Security/JSONLoad:
|
93
|
+
Enabled: true
|
94
|
+
Security/YAMLLoad:
|
95
|
+
Enabled: true
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.5.1
|
4
4
|
branches:
|
5
5
|
except:
|
6
6
|
- "/^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-.*)?/"
|
@@ -8,3 +8,8 @@ notifications:
|
|
8
8
|
email:
|
9
9
|
on_success: change
|
10
10
|
on_failure: always
|
11
|
+
before_install:
|
12
|
+
- gem install bundler -v '< 2'
|
13
|
+
script:
|
14
|
+
- bundle exec rubocop
|
15
|
+
- bundle exec rspec
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
usps_flags-grades (0.
|
5
|
-
usps_flags (~> 0.
|
4
|
+
usps_flags-grades (0.1.5)
|
5
|
+
usps_flags (~> 0.5, >= 0.5.5)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
ast (2.4.0)
|
10
11
|
diff-lcs (1.3)
|
11
12
|
docile (1.1.5)
|
12
13
|
file_utils (1.1.2)
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
jaro_winkler (1.5.2)
|
15
|
+
json (2.3.1)
|
16
|
+
mini_magick (4.10.1)
|
17
|
+
parallel (1.17.0)
|
18
|
+
parser (2.6.3.0)
|
19
|
+
ast (~> 2.4.0)
|
20
|
+
rainbow (3.0.0)
|
21
|
+
rake (12.3.3)
|
16
22
|
rspec (3.7.0)
|
17
23
|
rspec-core (~> 3.7.0)
|
18
24
|
rspec-expectations (~> 3.7.0)
|
@@ -26,16 +32,27 @@ GEM
|
|
26
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
33
|
rspec-support (~> 3.7.0)
|
28
34
|
rspec-support (3.7.0)
|
29
|
-
|
35
|
+
rubocop (0.71.0)
|
36
|
+
jaro_winkler (~> 1.5.1)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 2.6)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
42
|
+
rubocop-rspec (1.33.0)
|
43
|
+
rubocop (>= 0.60.0)
|
44
|
+
ruby-progressbar (1.10.1)
|
45
|
+
rubyzip (1.3.0)
|
30
46
|
simplecov (0.15.1)
|
31
47
|
docile (~> 1.1.0)
|
32
48
|
json (>= 1.8, < 3)
|
33
49
|
simplecov-html (~> 0.10.0)
|
34
50
|
simplecov-html (0.10.2)
|
35
|
-
|
51
|
+
unicode-display_width (1.6.0)
|
52
|
+
usps_flags (0.6.1)
|
36
53
|
file_utils (~> 1.1, >= 1.1.2)
|
37
|
-
mini_magick (~> 4.
|
38
|
-
rubyzip (~> 1.
|
54
|
+
mini_magick (~> 4.9, >= 4.9.4)
|
55
|
+
rubyzip (~> 1.3, >= 1.3.0)
|
39
56
|
|
40
57
|
PLATFORMS
|
41
58
|
ruby
|
@@ -43,6 +60,8 @@ PLATFORMS
|
|
43
60
|
DEPENDENCIES
|
44
61
|
rake (~> 12.2, >= 12.2.1)
|
45
62
|
rspec (~> 3.7, >= 3.7.0)
|
63
|
+
rubocop (~> 0.71, >= 0.71.0)
|
64
|
+
rubocop-rspec (~> 1.30, >= 1.30.0)
|
46
65
|
simplecov (~> 0.15, >= 0.15.1)
|
47
66
|
usps_flags-grades!
|
48
67
|
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/760b824f0edac3316a11/maintainability)](https://codeclimate.com/github/jfiander/usps-flags_grades/maintainability)
|
7
7
|
|
8
8
|
An extension for [USPSFlags](https://github.com/jfiander/usps-flags) to generate
|
9
|
-
|
9
|
+
grade insignia.
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
data/Rakefile
CHANGED
data/lib/usps_flags/grades.rb
CHANGED
@@ -1,123 +1,135 @@
|
|
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'
|
4
6
|
|
5
7
|
# Main class for generating grade and other insignia.
|
6
|
-
class USPSFlags
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
8
|
+
class USPSFlags
|
9
|
+
class Grades
|
10
|
+
require 'usps_flags/grades/grade'
|
11
|
+
require 'usps_flags/grades/membership'
|
12
|
+
require 'usps_flags/grades/edpro'
|
13
|
+
require 'usps_flags/grades/merit_marks'
|
14
|
+
|
15
|
+
ALL_CONFIGS ||= [
|
16
|
+
[:s, false, nil], [:p, false, nil], [:ap, false, nil], [:ap, true, nil],
|
17
|
+
[:jn, false, nil], [:jn, true, nil], [:n, false, nil], [:n, true, nil],
|
18
|
+
[:sn, false, nil], [nil, false, :senior], [nil, false, :life]
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
# Constructor for generating grade insignia.
|
22
|
+
#
|
23
|
+
# @example Generate JN with EdPro and Senior Member
|
24
|
+
# insignia = USPSFlags::Grades.new do |b|
|
25
|
+
# b.grade = :jn
|
26
|
+
# b.edpro = :edpro
|
27
|
+
# b.membership = :senior
|
28
|
+
# b.outfile = "/path/to/svg/output.svg"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# insignia.svg #=> Generates SVG file at "/path/to/svg/output.svg"
|
32
|
+
def initialize(options = {})
|
33
|
+
@grade = options[:grade]
|
34
|
+
@edpro = options[:edpro] || false
|
35
|
+
@membership = options[:membership]
|
36
|
+
@merit_marks = options[:merit_marks] || 0
|
37
|
+
@outfile = options[:outfile]
|
38
|
+
@generated_at = Time.now.strftime('%Y%m%d.%H%S%z')
|
39
|
+
yield self if block_given?
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
42
|
+
attr_accessor :grade
|
43
|
+
attr_accessor :edpro
|
44
|
+
attr_accessor :membership
|
45
|
+
attr_accessor :merit_marks
|
46
|
+
attr_accessor :outfile
|
47
|
+
|
48
|
+
# Generates the constructed file as SVG.
|
49
|
+
#
|
50
|
+
# @return [String] Returns the SVG file output path, or the svg data if no path was specified.
|
51
|
+
def svg
|
52
|
+
validate
|
53
|
+
@svg = <<~SVG
|
54
|
+
#{USPSFlags::Core.headers(title: title).gsub('0 0 3072 2048', '0 0 1024 682')}
|
55
|
+
<g transform="translate(0, 50)">
|
56
|
+
#{USPSFlags::Grades::Grade.get(@grade)}
|
57
|
+
#{USPSFlags::Grades::EdPro.get(@grade) if @edpro && USPSFlags::Grades::EdPro.for_grade(@grade)}
|
58
|
+
#{USPSFlags::Grades::Membership.get(@membership) unless @membership.nil?}
|
59
|
+
</g>
|
60
|
+
<g transform="translate(0, 450)">
|
61
|
+
#{USPSFlags::Grades::MeritMarks.get(@merit_marks)}
|
62
|
+
</g>
|
63
|
+
#{USPSFlags::Core.footer}
|
64
|
+
SVG
|
65
|
+
|
66
|
+
USPSFlags::Helpers.output(@svg, outfile: @outfile)
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
membership = case @membership
|
73
|
-
when :senior
|
74
|
-
" - Senior Member"
|
75
|
-
when :life
|
76
|
-
" - Life Member"
|
69
|
+
# Generates the constructed file as PNG.
|
70
|
+
#
|
71
|
+
# @return [String] Returns the PNG file output path.
|
72
|
+
def png(outfile: nil)
|
73
|
+
USPSFlags::Generate.png(svg, outfile: outfile)
|
74
|
+
outfile
|
77
75
|
end
|
78
76
|
|
79
|
-
|
80
|
-
|
77
|
+
# Generates the descriptive title for the SVG.
|
78
|
+
#
|
79
|
+
# @return [String] Returns the descriptive title.
|
80
|
+
def title
|
81
|
+
grade = @grade.to_s.upcase
|
82
|
+
edpro = ' - EdPro' if @edpro && @grade != :sn
|
83
|
+
membership = case @membership
|
84
|
+
when :senior
|
85
|
+
' - Senior Member'
|
86
|
+
when :life
|
87
|
+
' - Life Member'
|
88
|
+
end
|
89
|
+
|
90
|
+
"#{grade}#{edpro}#{membership}"
|
91
|
+
end
|
81
92
|
|
82
|
-
|
83
|
-
|
93
|
+
def self.all(dir = nil)
|
94
|
+
dir ||= USPSFlags.configuration.flags_dir
|
84
95
|
|
85
|
-
|
86
|
-
|
87
|
-
|
96
|
+
ALL_CONFIGS.each do |grade, edpro, membership|
|
97
|
+
path = "#{dir}/#{grade}"
|
98
|
+
path += '_edpro' if edpro
|
88
99
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
100
|
+
insignia = USPSFlags::Grades.new(
|
101
|
+
grade: grade, edpro: edpro, membership: membership,
|
102
|
+
outfile: "#{path}.svg"
|
103
|
+
)
|
93
104
|
|
94
|
-
|
105
|
+
USPSFlags::Generate.png(insignia.svg, outfile: "#{path}.png", trim: true)
|
106
|
+
end
|
95
107
|
end
|
96
|
-
end
|
97
108
|
|
98
109
|
private
|
99
110
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
111
|
+
def validate
|
112
|
+
validate_grade
|
113
|
+
validate_edpro
|
114
|
+
validate_membership
|
115
|
+
end
|
105
116
|
|
106
|
-
|
107
|
-
|
117
|
+
def validate_grade
|
118
|
+
return if @grade.nil? || USPSFlags::Grades::Grade.valid_grades.include?(@grade)
|
108
119
|
|
109
|
-
|
110
|
-
|
120
|
+
raise USPSFlags::Errors::InvalidInsignia, "Unknown grade: #{@grade}"
|
121
|
+
end
|
111
122
|
|
112
|
-
|
113
|
-
|
123
|
+
def validate_edpro
|
124
|
+
return if [true, false].include?(@edpro)
|
114
125
|
|
115
|
-
|
116
|
-
|
126
|
+
raise USPSFlags::Errors::InvalidInsignia, 'EdPro must be boolean'
|
127
|
+
end
|
117
128
|
|
118
|
-
|
119
|
-
|
129
|
+
def validate_membership
|
130
|
+
return if [nil, :senior, :life].include?(@membership)
|
120
131
|
|
121
|
-
|
132
|
+
raise USPSFlags::Errors::InvalidInsignia, "Unknown membership level: #{@membership}"
|
133
|
+
end
|
122
134
|
end
|
123
135
|
end
|