usps_flags 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2914b680d80ec58dd16d063e50dc6adde807de7
4
- data.tar.gz: e42467fd6b4739d4b5440a3897f698f03063f8b4
3
+ metadata.gz: 99d8700124e5242379c12635f83401644e2d2216
4
+ data.tar.gz: 0363226cb26fbfe1b85d3f45fbf8eabe24ecd209
5
5
  SHA512:
6
- metadata.gz: 443ab189736f15209dd5cd5e199654153370e4c7e7f6d0d89c764a216e444b8b12417dc93da41439b69658492aabb7ba5cbba11bca28e62130535196a504158b
7
- data.tar.gz: 6e8577fa46d0ca01a9e2614b5e20eb4d55a493eaa6527cc7f8d9f760601976160583465d26e7d976aeb7ba7a736f5257f85d9e8cb64480f0a6ff252b8ee80db1
6
+ metadata.gz: 66379243b5d54d074c1d06034f9090ac0d461f7fcf5952a355c6fc81a1a9f953acfad27874e89b3efab3e9dbe62e278eea7cfad2041cd22b4f2b6d95c9fb07b5
7
+ data.tar.gz: 4fb7463ab1c82513d27e366fa42ecf9e1d905e032d90f736b8e2e1f8aae8b53cf1a8d57207534fd870f5d40cb78d4524eb90c28d0dda6063963c21c2482330cf
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.2.2)
4
+ usps_flags (0.2.3)
5
5
  file_utils (~> 1.1, >= 1.1.2)
6
6
  mini_magick (~> 4.8, >= 4.8.0)
7
7
  rubyzip (~> 1.2, >= 1.2.1)
@@ -9,6 +9,8 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
+ codeclimate-test-reporter (0.6.0)
13
+ simplecov (>= 0.7.1, < 1.0.0)
12
14
  coveralls (0.8.21)
13
15
  json (>= 1.8, < 3)
14
16
  simplecov (~> 0.14.1)
@@ -49,6 +51,7 @@ PLATFORMS
49
51
  ruby
50
52
 
51
53
  DEPENDENCIES
54
+ codeclimate-test-reporter (~> 0.4, >= 0.4.8)
52
55
  coveralls (~> 0.8, >= 0.8.21)
53
56
  rake (~> 12.1, >= 12.1.0)
54
57
  rspec (~> 3.7, >= 3.7.0)
data/README.md CHANGED
@@ -21,7 +21,9 @@ gem 'usps_flags'
21
21
  Create the file `config/initializers/usps_flags.rb`:
22
22
 
23
23
  ```ruby
24
- USPSFlags::Config.flags_dir "#{Rails.root}/app/assets/images/flags"
24
+ USPSFlags::Config.new do |config|
25
+ config.flags_dir "#{Rails.root}/app/assets/images/flags"
26
+ end
25
27
  ```
26
28
 
27
29
  ### Other
@@ -119,17 +121,17 @@ USPSFlags::Generate.png svg_data, outfile: nil, trim: false
119
121
  You can also construct individual flags using the following syntax:
120
122
 
121
123
  ```ruby
122
- f = USPSFlags.new do
123
- type "LtC"
124
- scale 3
125
- field false
126
- trim true
127
- svg_file "/path/to/svg/output.svg"
128
- png_file "/path/to/png/output.png"
124
+ flag = USPSFlags.new do |f|
125
+ f.type = "LtC"
126
+ f.scale = 3
127
+ f.field = false
128
+ f.trim = true
129
+ f.svg_file = "/path/to/svg/output.svg"
130
+ f.png_file = "/path/to/png/output.png"
129
131
  end
130
132
 
131
- f.svg # Generate SVG file
132
- f.png # Generate PNG file
133
+ flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
134
+ flag.png #=> Generates PNG file at "/path/to/png/output.png"
133
135
  ```
134
136
 
135
137
  - Calling any DSL method without argument, or with `nil` as argument will return
@@ -7,75 +7,28 @@ class USPSFlags::Config
7
7
  BASE_FLY ||= 3072
8
8
  BASE_HOIST ||= BASE_FLY*2/3
9
9
  FRACTION_SCALE ||= 85
10
-
10
+
11
11
  @@flags_dir ||= "#{File.dirname(__dir__)}/output"
12
12
  @@use_larger_tridents ||= true
13
13
  @@log_fail_quietly ||= true
14
-
15
- # Accessor for the directory for storing generated flags.
14
+
15
+ # Configuration constructor
16
16
  #
17
- # @param [String] init If set, updates the path to the directory for storing generated flags.
18
- # @param [Boolean] reset Delete all files in the specified directory if found.
19
- # @example Update flag storage directory
20
- # # Rails.root => "/path/to"
21
- # USPSFlags::Config.flags_dir "#{Rails.root}/app/assets/images/flags" #=> "/path/to/app/assets/images/flags"
22
- # @example Update flag storage directory that already has some files in it
23
- # # Rails.root => "/path/to"
24
- # USPSFlags::Config.flags_dir "#{Rails.root}/app/assets/images/flags", reset: true #=> "/path/to/app/assets/images/flags"
25
- # @return [String] Returns the current (or updated) path to the flags directory.
26
- def self.flags_dir(init = nil, reset: false)
27
- unless init.nil?
28
- @@flags_dir = init
29
- ::FileUtils.rm_rf(USPSFlags::Config.flags_dir) if reset
30
- [
31
- "#{USPSFlags::Config.flags_dir}/SVG/insignia",
32
- "#{USPSFlags::Config.flags_dir}/PNG/insignia",
33
- "#{USPSFlags::Config.flags_dir}/ZIP"
34
- ].each do |dir|
35
- ::FileUtils.mkdir_p(dir)
36
- end
37
- ::FileUtils.mkdir_p(USPSFlags::Config.log_path) unless defined?(Rails)
38
- end
39
- @@flags_dir
17
+ # @param [String] flag_dir The path to the flags directory.
18
+ # @param [Boolean] use_larger_tridents Whether to use the larger trident configuration.
19
+ # @param [Boolean] log_fail_quietly Whether to print an error message if the log file is inaccessible.
20
+ # @param [Boolean] reset Whether to clear out the specified flags_dir.
21
+ def initialize
22
+ load_init_variables
23
+ yield self if block_given?
24
+ set_flags_dir(reset: @reset)
25
+ set_class_variables
40
26
  end
41
27
 
42
- # Alias for the directory to store generated log files.
43
- #
44
- # @example Rails
45
- # # Rails.root => "/path/to"
46
- # USPSFlags::Config.logs_dir #=> "/path/to/log"
47
- #
48
- # @example Non-Rails
49
- # USPSFlags::Config.logs_dir #=> "/app/root/log"
50
- def self.log_path
51
- if defined?(Rails)
52
- "#{Rails.root}/log"
53
- else
54
- log_dir = "#{self.flags_dir}/log"
55
- ::FileUtils.mkdir_p(log_dir)
56
- log_dir
57
- end
58
- end
59
-
60
- # Accessor for the boolean of whether to use the larger or smaller trident width.
61
- #
62
- # @param [Boolean] bool If set to a Boolean, specify whether to use the larger trident width.
63
- # @return [Boolean] Returns the current (or updated) setting.
64
- def self.use_larger_tridents(bool = nil)
65
- # Smaller: 1/2 in width on 24in x 16in field
66
- # Larger: 5/8 in width on 24in x 16in field
67
- @@use_larger_tridents = bool unless bool.nil? || !([true, false].include?(bool))
68
- @@use_larger_tridents
69
- end
70
-
71
- # Accessor for the boolean of whether to print an error message if the log file is inaccessible.
72
- #
73
- # @param [Boolean] bool If set to a Boolean, specify whether to print the error message.
74
- # @return [Boolean] Returns the current (or updated) setting.
75
- def self.log_fail_quietly(bool = nil)
76
- @@log_fail_quietly = bool if [true, false].include?(bool)
77
- @@log_fail_quietly
78
- end
28
+ attr_accessor :flags_dir
29
+ attr_accessor :reset
30
+ attr_accessor :use_larger_tridents
31
+ attr_accessor :log_fail_quietly
79
32
 
80
33
  # Base configuration values for trident insignia.
81
34
  #
@@ -122,4 +75,65 @@ class USPSFlags::Config
122
75
  circle_height_adj: USPSFlags::Config::BASE_FLY/800
123
76
  }
124
77
  end
78
+
79
+ # Accessor for the directory for storing generated flags.
80
+ #
81
+ # @return [String] The current path to the flags directory.
82
+ def self.flags_dir
83
+ @@flags_dir
84
+ end
85
+
86
+ # Alias for the directory to store generated log files.
87
+ #
88
+ # @return [String] The current path to the logs directory.
89
+ def self.log_path
90
+ log_path = if defined?(::Rails)
91
+ "#{::Rails.root}/log"
92
+ else
93
+ "#{@@flags_dir}/log"
94
+ end
95
+ ::FileUtils.mkdir_p(log_path)
96
+ log_path
97
+ end
98
+
99
+ # Accessor for the boolean of whether to use the larger or smaller trident width.
100
+ #
101
+ # @return [Boolean] Returns the current setting.
102
+ def self.use_larger_tridents
103
+ # Smaller: 1/2 in width on 24in x 16in field
104
+ # Larger: 5/8 in width on 24in x 16in field
105
+ @@use_larger_tridents
106
+ end
107
+
108
+ # Accessor for the boolean of whether to print an error message if the log file is inaccessible.
109
+ #
110
+ # @return [Boolean] Returns the current setting.
111
+ def self.log_fail_quietly
112
+ @@log_fail_quietly
113
+ end
114
+
115
+ private
116
+ def load_init_variables
117
+ @flags_dir = @@flags_dir
118
+ @use_larger_tridents = @@use_larger_tridents
119
+ @log_fail_quietly = @@log_fail_quietly
120
+ @reset = false
121
+ end
122
+
123
+ def set_flags_dir(reset: false)
124
+ ::FileUtils.rm_rf(@flags_dir) if reset
125
+ [
126
+ "#{@flags_dir}/SVG/insignia",
127
+ "#{@flags_dir}/PNG/insignia",
128
+ "#{@flags_dir}/ZIP"
129
+ ].each do |dir|
130
+ ::FileUtils.mkdir_p(dir)
131
+ end
132
+ end
133
+
134
+ def set_class_variables
135
+ @@flags_dir = @flags_dir
136
+ @@use_larger_tridents = @use_larger_tridents
137
+ @@log_fail_quietly = @log_fail_quietly
138
+ end
125
139
  end
data/lib/usps_flags.rb CHANGED
@@ -31,106 +31,64 @@ class USPSFlags
31
31
  # Constructor for individual flags.
32
32
  #
33
33
  # @example Generate insignia at default scale for Lt/C
34
- # f = USPSFlags.new do
35
- # type "LtC"
36
- # scale 3
37
- # field false
38
- # trim true
39
- # svg_file "/path/to/svg/output.svg"
40
- # png_file "/path/to/png/output.png"
34
+ # flag = USPSFlags.new do |f|
35
+ # f.type = "LtC"
36
+ # f.scale = 3
37
+ # f.field = false
38
+ # f.trim = true
39
+ # f.svg_file = "/path/to/svg/output.svg"
40
+ # f.png_file = "/path/to/png/output.png"
41
41
  # end
42
42
  #
43
- # f.svg #=> Generates SVG file at "/path/to/svg/output.svg"
44
- # f.png #=> Generates PNG file at "/path/to/png/output.png"
45
- def initialize(&block)
43
+ # flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
44
+ # flag.png #=> Generates PNG file at "/path/to/png/output.png"
45
+ def initialize
46
46
  @type = nil
47
47
  @svg_file = nil
48
48
  @png_file = nil
49
49
  @scale = nil
50
50
  @field = nil
51
51
  @trim = nil
52
- instance_eval(&block) if block_given?
52
+ yield self if block_given?
53
53
  end
54
54
 
55
55
  # Constructor accessor for the flag type.
56
56
  #
57
- # @param [String] type If set, updates the constructor's flag type.
58
- # @return [String] Returns the current (or updated) flag type.
59
- def type(string = nil)
60
- if string.nil?
61
- @type
62
- else
63
- @type = string
64
- self
65
- end
66
- end
57
+ # @param [String] type The type of flag to generate.
58
+ # @return [String]
59
+ attr_accessor :type
67
60
 
68
61
  # Constructor accessor for the SVG file output path.
69
62
  #
70
- # @param [String] svg_file If set, updates the constructor's SVG file output path.
63
+ # @param [String] svg_file The SVG file output path.
71
64
  # @return [String] Returns the current (or updated) SVG file output path.
72
- def svg_file(string = nil)
73
- if string.nil?
74
- @svg_file
75
- else
76
- @svg_file = string
77
- self
78
- end
79
- end
65
+ attr_accessor :svg_file
80
66
 
81
67
  # Constructor accessor for the PNG file output path.
82
68
  #
83
- # @param [String] png_file If set, updates the constructor's PNG file output path.
69
+ # @param [String] png_file The PNG file output path.
84
70
  # @return [String] Returns the current (or updated) PNG file output path.
85
- def png_file(string = nil)
86
- if string.nil?
87
- @png_file
88
- else
89
- @png_file = string
90
- self
91
- end
92
- end
71
+ attr_accessor :png_file
93
72
 
94
73
  # Constructor accessor for the image scale divisor factor.
95
74
  #
96
75
  # Available options are Float between 0 and 1, or Integer above 1.
97
76
  #
98
- # @param [Integer, Float] scale If set, updates the constructor's scale divisor factor.
77
+ # @param [Integer, Float] scale The scale divisor factor.
99
78
  # @return [Integer, Float] Returns the current (or updated) scaling factor.
100
- def scale(num = nil)
101
- if num.nil?
102
- @scale
103
- else
104
- @scale = num
105
- self
106
- end
107
- end
79
+ attr_accessor :scale
108
80
 
109
81
  # Constructor accessor for whether to generate the flag field (including any border).
110
82
  #
111
- # @param [Boolean] field If set, updates the constructor's field setting.
83
+ # @param [Boolean] field The field setting.
112
84
  # @return [Boolean] Returns the current (or updated) setting.
113
- def field(bool = nil)
114
- if bool.nil?
115
- @field
116
- else
117
- @field = bool
118
- self
119
- end
120
- end
85
+ attr_accessor :field
121
86
 
122
87
  # Constructor accessor for whether to trim the generated PNG file of excess transparency.
123
88
  #
124
- # @param [Boolean] trim If set, updates the constructor's trim setting.
89
+ # @param [Boolean] trim The trim setting.
125
90
  # @return [String] Returns the current (or updated) setting.
126
- def trim(bool = nil)
127
- if bool.nil?
128
- @trim
129
- else
130
- @trim = bool
131
- self
132
- end
133
- end
91
+ attr_accessor :trim
134
92
 
135
93
  # Generates the constructed file as SVG.
136
94
  #
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,8 @@ require 'coveralls'
2
2
  Coveralls.wear!
3
3
  require 'bundler/setup'
4
4
  Bundler.setup
5
+ require 'codeclimate-test-reporter'
6
+ CodeClimate::TestReporter.start
5
7
 
6
8
  require 'usps_flags'
7
9
 
@@ -6,10 +6,12 @@ describe USPSFlags::Config do
6
6
  default_flags_dir = File.dirname(__dir__).gsub("/spec", "/lib") + "/output"
7
7
  expect(USPSFlags::Config.flags_dir).to eql(default_flags_dir)
8
8
  end
9
+ end
9
10
 
10
- it "should return the new flags directory when given a new path" do
11
- new_flags_dir = "#{File.dirname(__dir__)}/flags"
12
- expect(USPSFlags::Config.flags_dir(new_flags_dir)).to eql(new_flags_dir)
11
+ describe "log_path" do
12
+ it "should return the current flags directory" do
13
+ default_log_path = File.dirname(__dir__).gsub("/spec", "/lib") + "/output/log"
14
+ expect(USPSFlags::Config.log_path).to eql(default_log_path)
13
15
  end
14
16
  end
15
17
 
@@ -24,4 +26,24 @@ describe USPSFlags::Config do
24
26
  expect([true, false]).to include(USPSFlags::Config.use_larger_tridents)
25
27
  end
26
28
  end
29
+
30
+ describe "log_fail_quietly" do
31
+ it "should return a Boolean from log_fail_quietly" do
32
+ expect([true, false]).to include(USPSFlags::Config.log_fail_quietly)
33
+ end
34
+ end
35
+
36
+ describe "configuration constructor" do
37
+ it "should return a properly constructed configuration" do
38
+ test_flags_dir = "./path/to/flags/for/spec"
39
+ @config = USPSFlags::Config.new do |config|
40
+ config.flags_dir = test_flags_dir
41
+ end
42
+
43
+ expect(@config.flags_dir).to eql(test_flags_dir)
44
+ expect(@config.reset).to eql(false)
45
+ expect(@config.use_larger_tridents).to eql(true)
46
+ expect(@config.log_fail_quietly).to eql(true)
47
+ end
48
+ end
27
49
  end
@@ -95,41 +95,40 @@ describe USPSFlags do
95
95
 
96
96
  describe "constructor" do
97
97
  it "should update type" do
98
- @flag.type "LtC"
98
+ @flag.type = "LtC"
99
99
  expect(@flag.type).to eql("LtC")
100
100
  end
101
101
 
102
102
  it "should update scale" do
103
- @flag.scale 4
103
+ @flag.scale = 4
104
104
  expect(@flag.scale).to eql(4)
105
105
  end
106
106
 
107
107
  it "should update field" do
108
- @flag.field false
108
+ @flag.field = false
109
109
  expect(@flag.field).to eql(false)
110
110
  end
111
111
 
112
112
  it "should update trim" do
113
- @flag.trim true
113
+ @flag.trim = true
114
114
  expect(@flag.trim).to eql(true)
115
115
  end
116
116
 
117
117
  it "should update svg_file" do
118
- @flag.svg_file "/path/to/svg/output.svg"
118
+ @flag.svg_file = "/path/to/svg/output.svg"
119
119
  expect(@flag.svg_file).to eql("/path/to/svg/output.svg")
120
120
  end
121
121
 
122
122
  it "should update png_file" do
123
- @flag.png_file "/path/to/png/output.png"
123
+ @flag.png_file = "/path/to/png/output.png"
124
124
  expect(@flag.png_file).to eql("/path/to/png/output.png")
125
125
  end
126
126
 
127
127
  describe "as configured" do
128
128
  before(:each) do
129
- @flag.type "LtC"
130
- @flag.scale 5
131
- @flag.svg_file ""
132
- @flag.svg
129
+ @flag.type = "LtC"
130
+ @flag.scale = 5
131
+ @flag.svg_file = ""
133
132
  end
134
133
 
135
134
  it "should construct and generate a flag with a valid header" do
data/usps_flags.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'usps_flags'
3
- s.version = '0.2.3'
3
+ s.version = '0.2.4'
4
4
  s.date = '2017-11-05'
5
5
  s.summary = 'Flag generator for United States Power Squadrons'
6
6
  s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency 'rake', '~> 12.1', '>= 12.1.0'
25
25
  s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
26
26
  s.add_development_dependency 'coveralls', '~> 0.8', '>= 0.8.21'
27
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4', '>= 0.4.8'
27
28
  end
data.tar.gz.sig CHANGED
Binary file
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.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -152,6 +152,26 @@ dependencies:
152
152
  - - ">="
153
153
  - !ruby/object:Gem::Version
154
154
  version: 0.8.21
155
+ - !ruby/object:Gem::Dependency
156
+ name: codeclimate-test-reporter
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '0.4'
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 0.4.8
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '0.4'
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 0.4.8
155
175
  description: A flag image (PNG, SVG) generator for United States Power Squadrons.
156
176
  email: julian@fiander.one
157
177
  executables: []
metadata.gz.sig CHANGED
Binary file