usps_flags 0.3.10 → 0.3.11

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
  SHA1:
3
- metadata.gz: 4d85ccc10a610da7a9847f5543e7d907ff15fd5e
4
- data.tar.gz: c7affbfa94639f5b621ed8c753a8d4f2a48ec8c7
3
+ metadata.gz: 912c06bbc43cfe66768f59b678da12adaecd9964
4
+ data.tar.gz: 44107e8638acf16858899949fc6b29198844f742
5
5
  SHA512:
6
- metadata.gz: f6524af08c48876941a3f3600ec93551d937e7fa45eaccf14efca7cc2122652db3c5fde7749b2fca2e478e881cfed8e9f88017bfa6abafb42212ab5ed80121ae
7
- data.tar.gz: 83dca9e5580e3405a92940525ed21cc33b26b59a3b41101b700d8b63f0ab32e8b96b18a5908a994255f015629f3bc81d1ad46c7cc3b1704cacdfdb4c55bbc91b
6
+ metadata.gz: eb93a2912820cc42b41a03d1c1deab2fb3caec1a2ccec47c9a0e2ab38e3e930ba1afbcf0510e22d1c6b6a032cdf2619bd4a6cebf413587938ad45a1d0c6b6688
7
+ data.tar.gz: bf314db590a8cd310e92155ba5dba21a5bde8773c21ab37faf1d0c6428144a3e554a01dcd392e9b84b15a2269593e9c5143b96b3feb93ddc72a5136dff22f084
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- XcȬ�4K�0��r��T��h!�պF::�'����� �+��(7-C�������)�f}vR�?�-�L ����@y��{?㥔繌!/��zUT�J;4���S����C
2
- [�.�S�S7-�I`i��lR|�r��fKzF4���Y{t15PFK����EVlKC~a��G#0<֧�<x {$1��k���d @�)4G�JpH�)��F�/�*H�2al'f��ä�V?��Ԕ*nj�g�
1
+ BwA[�zs���R1p����q�Ң^�������M�����̡��l����d*���>n
2
+ ����RK�ՖBӴPmb}E�|m�*Ԫ���YIf��Iw2���f/L P����j���jsI��8�!Z/xU}%kJ7��-C�!QXQ}�=_f튧�Ɓx���;큒���c<�\X6>qoL�Q'.��^˻\g�I b��g�GN�:l,��ܧ�Lӈc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.3.9)
4
+ usps_flags (0.3.11)
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)
data/README.md CHANGED
@@ -21,7 +21,7 @@ gem 'usps_flags'
21
21
  Create the file `config/initializers/usps_flags.rb`:
22
22
 
23
23
  ```ruby
24
- USPSFlags::Config.new do |config|
24
+ USPSFlags.configure do |config|
25
25
  config.flags_dir "#{Rails.root}/app/assets/images/flags"
26
26
  end
27
27
  ```
@@ -8,35 +8,27 @@ class USPSFlags::Config
8
8
  BASE_HOIST ||= BASE_FLY*2/3
9
9
  FRACTION_SCALE ||= 85
10
10
 
11
- @@flags_dir = "#{File.dirname(__dir__)}/output"
12
- @@use_larger_tridents = true
13
- @@reset = false
11
+ attr_accessor :flags_dir, :clear, :use_larger_tridents
14
12
 
15
13
  # Configuration constructor
16
14
  #
17
15
  # @param [String] flag_dir The path to the flags directory.
18
16
  # @param [Boolean] use_larger_tridents Whether to use the larger trident configuration.
19
- # @param [Boolean] reset Whether to clear out the specified flags_dir.
17
+ # @param [Boolean] clear Whether to clear out the specified flags_dir.
20
18
  def initialize
21
- load_init_variables
19
+ get_defaults
22
20
  yield self if block_given?
23
- set_class_variables
24
- set_flags_dir(reset: @reset)
25
21
  end
26
22
 
27
- attr_accessor :flags_dir
28
- attr_accessor :reset
29
- attr_accessor :use_larger_tridents
30
-
31
23
  # Base configuration values for trident insignia.
32
24
  #
33
25
  # All other values are derived from these, or directly from the constant sizes.
34
26
  #
35
27
  # @return [Hash] RThe configuration values for tridents.
36
- def self.trident
28
+ def trident
37
29
  point_height = USPSFlags::Config::BASE_FLY/48*17/8
38
30
  bar_width = USPSFlags::Config::BASE_FLY/48
39
- bar_width = bar_width*5/4 if self.use_larger_tridents
31
+ bar_width = bar_width*5/4 if USPSFlags.configuration.use_larger_tridents
40
32
  {
41
33
  height: trident_heights,
42
34
 
@@ -57,8 +49,8 @@ class USPSFlags::Config
57
49
  hash_width: USPSFlags::Config::BASE_FLY*3/32,
58
50
 
59
51
  delta_height: USPSFlags::Config::BASE_FLY*2/15,
60
- delta_gap_height: self.use_larger_tridents ? USPSFlags::Config::BASE_FLY*14/256 : USPSFlags::Config::BASE_FLY*17/256,
61
- delta_gap_width: self.use_larger_tridents ? bar_width*5/4 : bar_width*7/4,
52
+ delta_gap_height: USPSFlags.configuration.use_larger_tridents ? USPSFlags::Config::BASE_FLY*14/256 : USPSFlags::Config::BASE_FLY*17/256,
53
+ delta_gap_width: USPSFlags.configuration.use_larger_tridents ? bar_width*5/4 : bar_width*7/4,
62
54
  delta_width: USPSFlags::Config::BASE_FLY*43/768,
63
55
  delta_from_bottom: USPSFlags::Config::BASE_HOIST*11/64,
64
56
  delta_gap_scale: 0.40,
@@ -72,7 +64,7 @@ class USPSFlags::Config
72
64
  # Height values for trident insignia.
73
65
  #
74
66
  # @return [Hash] The height values for tridents.
75
- def self.trident_heights
67
+ def trident_heights
76
68
  {
77
69
  s: USPSFlags::Config::BASE_HOIST/2,
78
70
  d: USPSFlags::Config::BASE_HOIST*5/8,
@@ -81,68 +73,25 @@ class USPSFlags::Config
81
73
  }
82
74
  end
83
75
 
84
- # Accessor for the directory for storing generated flags.
85
- #
86
- # @return [String] The current path to the flags directory.
87
- def self.flags_dir
88
- @@flags_dir || if defined?(::Rails)
89
- "#{::Rails.root}/app/assets/images/usps-flags"
90
- else
91
- "#{File.dirname(__dir__)}/output"
92
- end
93
- end
94
-
95
76
  # Alias for the directory to store generated log files.
96
77
  #
97
78
  # @return [String] The current path to the logs directory.
98
- def self.log_path
99
- log_path = if defined?(::Rails)
79
+ def log_path
80
+ if defined?(::Rails)
100
81
  "#{::Rails.root}/log"
101
82
  else
102
- "#{@@flags_dir}/log"
83
+ "#{USPSFlags.configuration.flags_dir}/log"
103
84
  end
104
- ::FileUtils.mkdir_p(log_path)
105
- log_path
106
- end
107
-
108
- # Accessor for the boolean of whether to use the larger or smaller trident width.
109
- #
110
- # @return [Boolean] Returns the current setting.
111
- def self.use_larger_tridents
112
- # Smaller: 1/2 in width on 24in x 16in field
113
- # Larger: 5/8 in width on 24in x 16in field
114
- @@use_larger_tridents
115
- end
116
-
117
- # Accessor for the boolean of whether to clear the flags_dir.
118
- #
119
- # @return [Boolean] Returns the current setting.
120
- def self.reset
121
- @@reset
122
85
  end
123
86
 
124
87
  private
125
- def load_init_variables
126
- @flags_dir = @@flags_dir
127
- @use_larger_tridents = @@use_larger_tridents
128
- @reset = @@reset
129
- end
130
-
131
- def set_class_variables
132
- @@flags_dir = @flags_dir
133
- @@use_larger_tridents = @use_larger_tridents
134
- @@reset = @reset
135
- end
136
-
137
- def set_flags_dir(reset: false)
138
- return false if @@flags_dir.nil? || @@flags_dir.empty?
139
- ::FileUtils.rm_rf(@@flags_dir) if reset
140
- [
141
- "#{@@flags_dir}/SVG/insignia",
142
- "#{@@flags_dir}/PNG/insignia",
143
- "#{@@flags_dir}/ZIP"
144
- ].each do |dir|
145
- ::FileUtils.mkdir_p(dir)
88
+ def get_defaults
89
+ @flags_dir = if defined?(::Rails)
90
+ "#{::Rails.root}/app/assets/images/usps-flags"
91
+ else
92
+ "#{File.dirname(__dir__)}/output"
146
93
  end
94
+ @use_larger_tridents = true
95
+ @clear = false
147
96
  end
148
97
  end
@@ -41,7 +41,7 @@ class USPSFlags::Core::Trident
41
41
 
42
42
  private
43
43
  def load_config
44
- @trident_config = USPSFlags::Config.trident
44
+ @trident_config = USPSFlags.configuration.trident
45
45
  @main_spike_overhang = @trident_config[:bar_width] / 2
46
46
  @side_spike_overhang = @trident_config[:bar_width] / 2
47
47
  @top_point = ((USPSFlags::Config::BASE_HOIST - @trident_config[:height][@type]) / 2)
@@ -4,7 +4,7 @@
4
4
  # @private
5
5
  class USPSFlags::Core::TridentSpec
6
6
  def initialize(fly: 24, unit: "in")
7
- @trident_config = USPSFlags::Config.trident
7
+ @trident_config = USPSFlags.configuration.trident
8
8
  configure_sizes(fly)
9
9
  configure_labels(unit)
10
10
  end
@@ -103,15 +103,15 @@ class USPSFlags::Generate
103
103
  private
104
104
  def remove_static_files
105
105
  ["SVG", "PNG", "ZIP"].each do |dir|
106
- dir_path = "#{USPSFlags::Config.flags_dir}/#{dir}"
106
+ dir_path = "#{USPSFlags.configuration.flags_dir}/#{dir}"
107
107
  ::FileUtils.rm_rf(::Dir.glob("#{dir_path}/*")) if ::Dir.exist?(dir_path)
108
108
  end
109
- ["SVG/insignia", "PNG/insignia"].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags::Config.flags_dir}/#{dir}") }
109
+ ["SVG/insignia", "PNG/insignia"].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags.configuration.flags_dir}/#{dir}") }
110
110
  USPSFlags::Helpers.log "\n - Cleared previous files.\n"
111
111
  end
112
112
 
113
113
  def set_file_paths
114
- @svg_file = "#{USPSFlags::Config.flags_dir}/SVG/#{@flag}.svg"
114
+ @svg_file = "#{USPSFlags.configuration.flags_dir}/SVG/#{@flag}.svg"
115
115
  @png_file = @svg_file.gsub("/SVG/", "/PNG/").gsub(".svg", ".png")
116
116
  @svg_ins_file = @svg_file.gsub("/SVG/", "/SVG/insignia/")
117
117
  @png_ins_file = @svg_file.gsub("/SVG/", "/PNG/insignia/").gsub(".svg", ".png")
@@ -122,20 +122,20 @@ class USPSFlags::Generate
122
122
  puts "\nSVGs generate a single file.",
123
123
  "PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.",
124
124
  "Corresponding rank insignia (including smaller sizes) are also generated, as appropriate."
125
- USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags::Config.flags_dir}\n"
125
+ USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags.configuration.flags_dir}\n"
126
126
  USPSFlags::Helpers.log "\n#{Time.now.strftime('%Y%m%d.%H%M%S%z')} – Generating static files...\n\n"
127
127
  USPSFlags::Helpers.log "Flag | SVG | PNG | Run time\n".rjust(USPSFlags::Helpers.max_flag_name_length+31),
128
128
  "\n".rjust(USPSFlags::Helpers.max_flag_name_length+32, "-")
129
129
  end
130
130
 
131
131
  def generate_zip(type)
132
- raise USPSFlags::Errors::ZipGenerationError, "Flags directory not found." unless ::Dir.exist?("#{USPSFlags::Config.flags_dir}/ZIP")
132
+ raise USPSFlags::Errors::ZipGenerationError, "Flags directory not found." unless ::Dir.exist?("#{USPSFlags.configuration.flags_dir}/ZIP")
133
133
 
134
- zip = "#{USPSFlags::Config.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
134
+ zip = "#{USPSFlags.configuration.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
135
135
  ::File.delete(zip) if ::File.exist?(zip)
136
136
 
137
137
  ::Zip::File.open(zip, Zip::File::CREATE) do |z|
138
- ::Dir.glob("#{USPSFlags::Config.flags_dir}/#{type.upcase}/**/*").each do |f|
138
+ ::Dir.glob("#{USPSFlags.configuration.flags_dir}/#{type.upcase}/**/*").each do |f|
139
139
  add_to_zip(z, f)
140
140
  end
141
141
  end
@@ -200,7 +200,7 @@ class USPSFlags::Generate
200
200
  def generate_reduced_size_pngs
201
201
  USPSFlags::Helpers.png_sizes.keys.each do |size|
202
202
  size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: @flag)
203
- @sized_png_file = "#{USPSFlags::Config.flags_dir}/PNG/#{@flag}.#{size_key}.png"
203
+ @sized_png_file = "#{USPSFlags.configuration.flags_dir}/PNG/#{@flag}.#{size_key}.png"
204
204
  @sized_png_ins_file = @sized_png_file.gsub("/PNG/", "/PNG/insignia/")
205
205
 
206
206
  generate_smaller_png(size, size_key)
@@ -29,7 +29,7 @@ class USPSFlags::Helpers
29
29
  # @param [String] size_key Size suffix to attach to the file name.
30
30
  def resize_png(png_file, file: nil, outfile: nil, size:, size_key:)
31
31
  raise USPSFlags::Errors::PNGConversionError if outfile.nil? && file.nil?
32
- output_file_name = outfile || "#{USPSFlags::Config.flags_dir}/PNG/#{file}.#{size_key}.png"
32
+ output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
33
33
  MiniMagick::Tool::Convert.new do |convert|
34
34
  convert << "-background" << "none"
35
35
  convert << "-format" << "png"
@@ -93,10 +93,10 @@ class USPSFlags::Helpers
93
93
  # This should never need to be called directly.
94
94
  # @private
95
95
  def log(*messages)
96
- ::FileUtils.mkdir_p(USPSFlags::Config.log_path)
96
+ ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
97
97
  outputs = [STDOUT]
98
98
 
99
- log_file = File.open("#{USPSFlags::Config.log_path}/flag.log", 'a')
99
+ log_file = File.open("#{USPSFlags.configuration.log_path}/flag.log", 'a')
100
100
  outputs << log_file
101
101
 
102
102
  messages.each do |message|
data/lib/usps_flags.rb CHANGED
@@ -29,6 +29,33 @@ class USPSFlags
29
29
  require "usps_flags/helpers/#{d}"
30
30
  end
31
31
 
32
+ class << self
33
+ attr_accessor :configuration
34
+ end
35
+
36
+ # Configuration accessor.
37
+ def self.configuration
38
+ @configuration ||= USPSFlags::Config.new
39
+ end
40
+
41
+ # Configuration constructor.
42
+ def self.configure
43
+ yield(configuration)
44
+ self.ensure_directories
45
+ @configuration
46
+ end
47
+
48
+ # Ensures the directory structure exists.
49
+ #
50
+ # @private
51
+ def self.ensure_directories
52
+ ::FileUtils.rm_rf(@configuration.flags_dir) if @configuration.clear
53
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/PNG/insignia")
54
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/SVG/insignia")
55
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/ZIP")
56
+ ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
57
+ end
58
+
32
59
  # Constructor for individual flags.
33
60
  #
34
61
  # @example Generate insignia at default scale for Lt/C
@@ -53,43 +80,15 @@ class USPSFlags
53
80
  yield self if block_given?
54
81
  end
55
82
 
56
- # Constructor accessor for the flag type.
83
+ # Constructor accessors.
57
84
  #
58
85
  # @param [String] type The type of flag to generate.
59
- # @return [String]
60
- attr_accessor :type
61
-
62
- # Constructor accessor for the SVG file output path.
63
- #
64
86
  # @param [String] svg_file The SVG file output path.
65
- # @return [String] Returns the current (or updated) SVG file output path.
66
- attr_accessor :svg_file
67
-
68
- # Constructor accessor for the PNG file output path.
69
- #
70
87
  # @param [String] png_file The PNG file output path.
71
- # @return [String] Returns the current (or updated) PNG file output path.
72
- attr_accessor :png_file
73
-
74
- # Constructor accessor for the image scale divisor factor.
75
- #
76
- # Available options are Float between 0 and 1, or Integer above 1.
77
- #
78
88
  # @param [Integer, Float] scale The scale divisor factor.
79
- # @return [Integer, Float] Returns the current (or updated) scaling factor.
80
- attr_accessor :scale
81
-
82
- # Constructor accessor for whether to generate the flag field (including any border).
83
- #
84
89
  # @param [Boolean] field The field setting.
85
- # @return [Boolean] Returns the current (or updated) setting.
86
- attr_accessor :field
87
-
88
- # Constructor accessor for whether to trim the generated PNG file of excess transparency.
89
- #
90
90
  # @param [Boolean] trim The trim setting.
91
- # @return [String] Returns the current (or updated) setting.
92
- attr_accessor :trim
91
+ attr_accessor :type, :svg_file, :png_file, :scale, :field, :trim
93
92
 
94
93
  # Generates the constructed file as SVG.
95
94
  #
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,7 @@ RSpec.configure do |config|
13
13
  $tmp_flags_dir = "tmp/flags"
14
14
  $tmp_alt_flags_dir = "tmp/alt_flags"
15
15
 
16
- USPSFlags::Config.new do |c|
16
+ USPSFlags.configure do |c|
17
17
  c.flags_dir = $tmp_flags_dir
18
18
  end
19
19
  end
@@ -3,38 +3,38 @@ require 'spec_helper'
3
3
  describe USPSFlags::Config do
4
4
  describe "class variable accessors" do
5
5
  it "should return the current flags directory" do
6
- expect(USPSFlags::Config.flags_dir).to eql($tmp_flags_dir)
6
+ expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
7
7
  end
8
8
 
9
9
  it "should return the current flags directory" do
10
10
  default_log_path = $tmp_flags_dir + "/log"
11
- expect(USPSFlags::Config.log_path).to eql(default_log_path)
11
+ expect(USPSFlags.configuration.log_path).to eql(default_log_path)
12
12
  end
13
13
 
14
14
  it "should return a Boolean from use_larger_tridents" do
15
- expect([true, false]).to include(USPSFlags::Config.use_larger_tridents)
15
+ expect([true, false]).to include(USPSFlags.configuration.use_larger_tridents)
16
16
  end
17
17
 
18
- it "should return a Boolean from reset" do
19
- expect([true, false]).to include(USPSFlags::Config.reset)
18
+ it "should return a Boolean from clear" do
19
+ expect([true, false]).to include(USPSFlags.configuration.clear)
20
20
  end
21
21
  end
22
22
 
23
23
  describe "trident" do
24
24
  it "should return a Hash from trident" do
25
- expect(USPSFlags::Config.trident).to be_a(Hash)
25
+ expect(USPSFlags.configuration.trident).to be_a(Hash)
26
26
  end
27
27
  end
28
28
 
29
29
  describe "configuration constructor" do
30
30
  it "should return a properly constructed configuration" do
31
- @config = USPSFlags::Config.new do |config|
31
+ USPSFlags.configure do |config|
32
32
  config.flags_dir = $tmp_flags_dir
33
33
  end
34
34
 
35
- expect(@config.flags_dir).to eql($tmp_flags_dir)
36
- expect(@config.reset).to eql(false)
37
- expect(@config.use_larger_tridents).to eql(true)
35
+ expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
36
+ expect(USPSFlags.configuration.clear).to eql(false)
37
+ expect(USPSFlags.configuration.use_larger_tridents).to eql(true)
38
38
  end
39
39
  end
40
40
 
@@ -52,7 +52,7 @@ describe USPSFlags::Config do
52
52
  end
53
53
 
54
54
  it "should use the default Rails log directory" do
55
- expect(USPSFlags::Config.log_path).to eql("tmp/rails_app/log")
55
+ expect(@config.log_path).to eql("tmp/rails_app/log")
56
56
  end
57
57
  end
58
58
  end
@@ -176,7 +176,7 @@ describe USPSFlags::Generate do
176
176
  end
177
177
 
178
178
  it "should not raise an error while generating all static files" do
179
- png_dir = "#{USPSFlags::Config.flags_dir}/PNG"
179
+ png_dir = "#{USPSFlags.configuration.flags_dir}/PNG"
180
180
  ::FileUtils.cp("spec/assets/1LT.thumb.png", "#{png_dir}/insignia/1LT.thumb.png")
181
181
  ::FileUtils.cp("spec/assets/LT.png", "#{png_dir}/insignia/LT.png")
182
182
  ::FileUtils.cp("spec/assets/FLT.png", "#{png_dir}/FLT.png")
@@ -223,7 +223,7 @@ describe USPSFlags::Generate do
223
223
  Generated PNG Zip
224
224
  LOG
225
225
 
226
- log_contents = ::File.read("#{USPSFlags::Config.log_path}/flag.log")
226
+ log_contents = ::File.read("#{USPSFlags.configuration.log_path}/flag.log")
227
227
 
228
228
  expect(log_contents).to match(Regexp.new(correct_log_pattern))
229
229
  end
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.3.10'
3
+ s.version = '0.3.11'
4
4
  s.date = '2017-11-08'
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.'
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.3.10
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
metadata.gz.sig CHANGED
Binary file