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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f9ab5d165c202f4af2a99caa777e90a0f5df7a4b06fd8de58fa9d3d3a86079d
4
- data.tar.gz: 5a54878338bdb11837dafa04550092da604b4f86ebdd5ae68a08410597f32c20
3
+ metadata.gz: cefac45cc5531db3f4f992a90e1b527a7e743aaf982a6266d6b6fb30d2256e17
4
+ data.tar.gz: 732876a050800e686568512f63274b38ad6a296ceab6f0b777bb4085b6de07a8
5
5
  SHA512:
6
- metadata.gz: b7b2a9a9438a142a22991c594c9c36c11859cb4066f3f0995bcc31a2e9f5693b1298298b06fc72faf45135421cbb54fa3b37d081d356fc596d3c31e246877e0a
7
- data.tar.gz: 1e210586ed6693d2708e17ca7dee3026de42e5afd9db08a0ef174957ba5a9d28dc61fdd65e039aecd19dcce09f82500f34b4a44fa5a3460ba229e477daace60b
6
+ metadata.gz: db74e2ca7a56c73a99f1cdc90bbaaade93598c7c44fd662af77c0586d98c58a93c19cf41bb802a1f8225e5610d03df24f78e95e922c909a328e41521b0620bdc
7
+ data.tar.gz: b70066bc684b2c02de5b54c010955b3a9cc1efdcb32b85e44c9fa83a928a39e1989ec1b661370680425bfed860c60bf0cf76bc37cbd5d5e848f6b6523bc29a3a
@@ -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
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.1
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
@@ -1,2 +1,4 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
  gemspec
@@ -1,18 +1,24 @@
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.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
- json (2.1.0)
14
- mini_magick (4.9.3)
15
- rake (12.2.1)
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
- rubyzip (1.2.3)
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
- usps_flags (0.4.1)
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.8, >= 4.8.0)
38
- rubyzip (~> 1.2, >= 1.2.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
- regrade insignia.
9
+ grade insignia.
10
10
 
11
11
  ## Usage
12
12
 
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,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::Grades
7
- require 'usps_flags/grades/grade'
8
- require 'usps_flags/grades/membership'
9
- require 'usps_flags/grades/edpro'
10
- require 'usps_flags/grades/merit_marks'
11
-
12
- ALL_CONFIGS ||= [
13
- [:s, false, nil], [:p, false, nil], [:ap, false, nil], [:ap, true, nil],
14
- [:jn, false, nil], [:jn, true, nil], [:n, false, nil], [:n, true, nil],
15
- [:sn, false, nil], [nil, false, :senior], [nil, false, :life]
16
- ].freeze
17
-
18
- # Constructor for generating grade insignia.
19
- #
20
- # @example Generate JN with EdPro and Senior Member
21
- # insignia = USPSFlags::Grades.new do |b|
22
- # b.grade = :jn
23
- # b.edpro = :edpro
24
- # b.membership = :senior
25
- # b.outfile = "/path/to/svg/output.svg"
26
- # end
27
- #
28
- # insignia.svg #=> Generates SVG file at "/path/to/svg/output.svg"
29
- def initialize(options = {})
30
- @grade = options[:grade] || nil
31
- @edpro = options[:edpro] || false
32
- @membership = options[:membership] || nil
33
- @merit_marks = options[:merit_marks] || 0
34
- @outfile = options[:outfile] || nil
35
- @generated_at = Time.now.strftime("%Y%m%d.%H%S%z")
36
- yield self if block_given?
37
- end
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
- attr_accessor :grade
40
- attr_accessor :edpro
41
- attr_accessor :membership
42
- attr_accessor :merit_marks
43
- attr_accessor :outfile
44
-
45
- # Generates the constructed file as SVG.
46
- #
47
- # @return [String] Returns the SVG file output path, or the svg data if no path was specified.
48
- def svg
49
- validate
50
- @svg = <<~SVG
51
- #{USPSFlags::Core.headers(title: title).gsub('0 0 3072 2048', '0 0 1024 682')}
52
- <g transform="translate(0, 50)">
53
- #{USPSFlags::Grades::Grade.get(@grade)}
54
- #{USPSFlags::Grades::EdPro.get(@grade) if @edpro && USPSFlags::Grades::EdPro.for_grade(@grade)}
55
- #{USPSFlags::Grades::Membership.get(@membership) unless @membership.nil?}
56
- </g>
57
- <g transform="translate(0, 450)">
58
- #{USPSFlags::Grades::MeritMarks.get(@merit_marks)}
59
- </g>
60
- #{USPSFlags::Core.footer}
61
- SVG
62
-
63
- USPSFlags::Helpers.output(@svg, outfile: @outfile)
64
- end
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
- # Generates the descriptive title for the SVG.
67
- #
68
- # @return [String] Returns the descriptive title.
69
- def title
70
- grade = @grade.to_s.upcase
71
- edpro = " - EdPro" if @edpro && @grade != :sn
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
- "#{grade}#{edpro}#{membership}"
80
- end
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
- def self.all(dir = nil)
83
- dir ||= USPSFlags.configuration.flags_dir
93
+ def self.all(dir = nil)
94
+ dir ||= USPSFlags.configuration.flags_dir
84
95
 
85
- ALL_CONFIGS.each do |grade, edpro, membership|
86
- path = "#{dir}/#{grade}"
87
- path += '_edpro' if edpro
96
+ ALL_CONFIGS.each do |grade, edpro, membership|
97
+ path = "#{dir}/#{grade}"
98
+ path += '_edpro' if edpro
88
99
 
89
- insignia = USPSFlags::Grades.new(
90
- grade: grade, edpro: edpro, membership: membership,
91
- outfile: "#{path}.svg"
92
- )
100
+ insignia = USPSFlags::Grades.new(
101
+ grade: grade, edpro: edpro, membership: membership,
102
+ outfile: "#{path}.svg"
103
+ )
93
104
 
94
- USPSFlags::Generate.png(insignia.svg, outfile: "#{path}.png", trim: true)
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
- def validate
101
- validate_grade
102
- validate_edpro
103
- validate_membership
104
- end
111
+ def validate
112
+ validate_grade
113
+ validate_edpro
114
+ validate_membership
115
+ end
105
116
 
106
- def validate_grade
107
- return if @grade.nil? || USPSFlags::Grades::Grade.valid_grades.include?(@grade)
117
+ def validate_grade
118
+ return if @grade.nil? || USPSFlags::Grades::Grade.valid_grades.include?(@grade)
108
119
 
109
- raise USPSFlags::Errors::InvalidInsignia, "Unknown grade: #{@grade}"
110
- end
120
+ raise USPSFlags::Errors::InvalidInsignia, "Unknown grade: #{@grade}"
121
+ end
111
122
 
112
- def validate_edpro
113
- return if [true, false].include?(@edpro)
123
+ def validate_edpro
124
+ return if [true, false].include?(@edpro)
114
125
 
115
- raise USPSFlags::Errors::InvalidInsignia, "EdPro must be boolean"
116
- end
126
+ raise USPSFlags::Errors::InvalidInsignia, 'EdPro must be boolean'
127
+ end
117
128
 
118
- def validate_membership
119
- return if [nil, :senior, :life].include?(@membership)
129
+ def validate_membership
130
+ return if [nil, :senior, :life].include?(@membership)
120
131
 
121
- raise USPSFlags::Errors::InvalidInsignia, "Unknown membership level: #{@membership}"
132
+ raise USPSFlags::Errors::InvalidInsignia, "Unknown membership level: #{@membership}"
133
+ end
122
134
  end
123
135
  end