usps_flags 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -11
  3. data/.travis.yml +1 -1
  4. data/Gemfile.lock +5 -2
  5. data/README.md +6 -0
  6. data/lib/usps_flags.rb +35 -44
  7. data/lib/usps_flags/config.rb +89 -87
  8. data/lib/usps_flags/core.rb +44 -42
  9. data/lib/usps_flags/core/ensign.rb +53 -49
  10. data/lib/usps_flags/core/field.rb +96 -92
  11. data/lib/usps_flags/core/footer.rb +9 -5
  12. data/lib/usps_flags/core/headers.rb +58 -48
  13. data/lib/usps_flags/core/icons.rb +11 -7
  14. data/lib/usps_flags/core/icons/anchor.rb +62 -56
  15. data/lib/usps_flags/core/icons/binoculars.rb +21 -15
  16. data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
  17. data/lib/usps_flags/core/icons/star.rb +21 -15
  18. data/lib/usps_flags/core/icons/trident.rb +136 -127
  19. data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
  20. data/lib/usps_flags/core/icons/trumpet.rb +34 -28
  21. data/lib/usps_flags/core/pennant.rb +50 -46
  22. data/lib/usps_flags/core/trident_spec.rb +135 -131
  23. data/lib/usps_flags/core/trident_specs.rb +11 -7
  24. data/lib/usps_flags/core/trident_specs/base.rb +36 -26
  25. data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
  26. data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
  27. data/lib/usps_flags/core/trident_specs/header.rb +56 -50
  28. data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
  29. data/lib/usps_flags/core/trident_specs/long.rb +41 -25
  30. data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
  31. data/lib/usps_flags/core/trident_specs/short.rb +30 -156
  32. data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
  33. data/lib/usps_flags/core/tridents.rb +54 -50
  34. data/lib/usps_flags/core/us.rb +40 -44
  35. data/lib/usps_flags/core/wheel.rb +7 -3
  36. data/lib/usps_flags/errors.rb +25 -23
  37. data/lib/usps_flags/generate.rb +111 -107
  38. data/lib/usps_flags/generate/flag.rb +160 -157
  39. data/lib/usps_flags/generate/generator_methods.rb +139 -0
  40. data/lib/usps_flags/generate/helper_methods.rb +88 -0
  41. data/lib/usps_flags/helpers.rb +163 -165
  42. data/lib/usps_flags/helpers/builders.rb +92 -85
  43. data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
  44. data/lib/usps_flags/helpers/valid_flags.rb +45 -41
  45. data/lib/usps_flags/rational.rb +35 -0
  46. data/spec/usps_flags/config_spec.rb +17 -10
  47. data/spec/usps_flags/core_spec.rb +31 -31
  48. data/spec/usps_flags/generate_spec.rb +76 -73
  49. data/spec/usps_flags/helpers_spec.rb +8 -8
  50. data/spec/usps_flags/rational_spec.rb +17 -0
  51. data/spec/usps_flags_spec.rb +19 -21
  52. data/usps_flags.gemspec +7 -6
  53. metadata +34 -10
  54. data/lib/rational.rb +0 -39
  55. data/lib/usps_flags/generate/private.rb +0 -199
  56. data/spec/rational_spec.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00b32e5fbfbb5d0d90e1f3f449e96b89c5d3d52de7a9ea6ae6a042609bb69665
4
- data.tar.gz: c35ad25ec8df45961cbf57829109ad05eacba524daf1674751f2649322ad5479
3
+ metadata.gz: 3a401780854a7517c7b211d59ae8c64d99f2190ece54927c9db84fea2bf33957
4
+ data.tar.gz: cd332320e247bd219bf094a72ab6c31a57fb642fefdc3cab889a4fb26b32cfc4
5
5
  SHA512:
6
- metadata.gz: 451d050441eb4de435dc9f4463d8fcbe04b9b58d17264ce5fac69dc60d1578597f91069ba536e75fe7ed44faaca64dde43cc5c07175fb386776373e0cb5ec5d7
7
- data.tar.gz: 16fd6eaf1886833465bb5a8e16a25a70b1ff381447d90fda55117d402247bb6552669b20d6d0792842bcdb4cbf473d409edc8d87dfad48091ff196c7c488a404
6
+ metadata.gz: a7d4c6dd949fb0402e768a3347610cf417c2926eddbb99fe319721bb4d09595d2f9886b52bcbb88728dfa6b1d556d839e992e01b4c70a62a0ceef997996f81e4
7
+ data.tar.gz: 0d4ab1879a6d9fc1616a8fd7b1532dd50900a824d39b958679fecbc05ab8966a64d8bb48aa5ff505d5a43ce5eb4dd764b030c0063f4fba9e4ced7ab3c1e27ece
@@ -2,9 +2,11 @@ require: rubocop-rspec
2
2
  AllCops:
3
3
  TargetRubyVersion: 2.5
4
4
  Exclude:
5
+ - lib/output/*
5
6
  - tmp/**/*
7
+ - vendor/**/*
6
8
 
7
- Layout/IndentHash:
9
+ Layout/IndentFirstHashElement:
8
10
  EnforcedStyle: consistent
9
11
  Layout/AccessModifierIndentation:
10
12
  EnforcedStyle: outdent
@@ -24,6 +26,8 @@ Layout/SpaceInsideHashLiteralBraces:
24
26
  EnforcedStyleForEmptyBraces: no_space
25
27
  Layout/SpaceInsideArrayLiteralBrackets:
26
28
  EnforcedStyle: no_space
29
+ Layout/EndAlignment:
30
+ EnforcedStyleAlignWith: start_of_line
27
31
 
28
32
  Lint/UnusedMethodArgument:
29
33
  Enabled: true
@@ -34,12 +38,6 @@ Metrics/BlockLength:
34
38
  Exclude:
35
39
  - 'spec/**/*.rb'
36
40
  Metrics/LineLength:
37
- Exclude:
38
- - 'spec/**/*.rb'
39
- Max: 100
40
- Metrics/LineLength:
41
- Include:
42
- - 'spec/**/*.rb'
43
41
  Max: 120
44
42
  Metrics/MethodLength:
45
43
  Enabled: true
@@ -53,11 +51,19 @@ Metrics/CyclomaticComplexity:
53
51
  Metrics/AbcSize:
54
52
  Enabled: true
55
53
 
56
- Rails/InverseOf:
57
- Enabled: true
54
+ Naming/UncommunicativeMethodParamName:
55
+ Enabled: false
56
+ Naming/AccessorMethodName:
57
+ Enabled: false
58
58
 
59
59
  RSpec/MessageSpies:
60
60
  EnforcedStyle: receive
61
+ RSpec/InstanceVariable:
62
+ Enabled: false
63
+ RSpec/NestedGroups:
64
+ Enabled: false
65
+ RSpec/ExampleLength:
66
+ Enabled: false
61
67
 
62
68
  Style/Documentation:
63
69
  Enabled: false
@@ -73,12 +79,17 @@ Style/ClassCheck:
73
79
  Enabled: true
74
80
  Style/GuardClause:
75
81
  Enabled: true
82
+ Style/ClassAndModuleChildren:
83
+ EnforcedStyle: nested
84
+ Style/GlobalVars:
85
+ Exclude:
86
+ - 'spec/**/*.rb'
87
+ Style/ParallelAssignment:
88
+ Enabled: false
76
89
 
77
90
  Security/Eval:
78
91
  Enabled: true
79
92
  Security/JSONLoad:
80
93
  Enabled: true
81
- Security/JSONLoad:
82
- Enabled: true
83
94
  Security/YAMLLoad:
84
95
  Enabled: true
@@ -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]+(?:-.*)?/"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.5.0)
4
+ usps_flags (0.5.1)
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)
@@ -41,6 +41,8 @@ GEM
41
41
  rainbow (>= 2.2.2, < 4.0)
42
42
  ruby-progressbar (~> 1.7)
43
43
  unicode-display_width (>= 1.4.0, < 1.7)
44
+ rubocop-rspec (1.33.0)
45
+ rubocop (>= 0.60.0)
44
46
  ruby-progressbar (1.10.1)
45
47
  rubyzip (1.2.3)
46
48
  simplecov (0.15.1)
@@ -56,7 +58,8 @@ PLATFORMS
56
58
  DEPENDENCIES
57
59
  rake (~> 12.2, >= 12.2.1)
58
60
  rspec (~> 3.7, >= 3.7.0)
59
- rubocop (~> 0.59, >= 0.59.2)
61
+ rubocop (~> 0.71, >= 0.71.0)
62
+ rubocop-rspec (~> 1.30, >= 1.30.0)
60
63
  simplecov (~> 0.15, >= 0.15.1)
61
64
  usps_flags!
62
65
 
data/README.md CHANGED
@@ -125,6 +125,12 @@ flag = USPSFlags.new do |f|
125
125
  f.png_file = "/path/to/png/output.png"
126
126
  end
127
127
 
128
+ flag = USPSFlags.new(
129
+ type: "LtC", scale: 3, field: false, trim: true,
130
+ svg_file: "/path/to/svg/output.svg",
131
+ png_file: "/path/to/png/output.png"
132
+ )
133
+
128
134
  flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
129
135
  flag.png #=> Generates PNG file at "/path/to/png/output.png"
130
136
  ```
@@ -1,33 +1,28 @@
1
1
  # frozen_string_literal: false
2
2
 
3
- # Base class for the namespace. Provides a constructor DSL.
3
+ # Main module for the namespace.
4
4
  #
5
5
  # @author Julian Fiander
6
6
  # @since 0.1.5
7
7
  class USPSFlags
8
+ MODULES ||= {
9
+ 'usps_flags' => %w[rational config helpers core generate errors],
10
+ 'usps_flags/helpers' => %w[builders spec_arrows],
11
+ 'usps_flags/core' => %w[
12
+ icons ensign field footer headers pennant tridents trident_specs trident_spec us wheel
13
+ ],
14
+ 'usps_flags/generate' => %w[flag]
15
+ }.freeze
16
+
8
17
  require 'fileutils'
9
18
  require 'zip'
10
19
  require 'mini_magick'
11
- require 'rational'
12
-
13
- %w[config helpers core generate errors].each do |d|
14
- require "usps_flags/#{d}"
15
- end
16
-
17
- %w[builders spec_arrows].each do |d|
18
- require "usps_flags/helpers/#{d}"
19
- end
20
20
 
21
- %w[icons ensign field footer headers pennant tridents trident_specs trident_spec us wheel].each do |d|
22
- require "usps_flags/core/#{d}"
23
- end
24
-
25
- %w[flag].each do |d|
26
- require "usps_flags/generate/#{d}"
27
- end
28
-
29
- class << self
30
- attr_accessor :configuration
21
+ MODULES.each do |parent, bases|
22
+ bases.each do |base|
23
+ res = require("#{parent}/#{base}")
24
+ puts "#{parent}/#{base}: #{res}" if ENV['VERBOSE_REQUIRE'] == 'true'
25
+ end
31
26
  end
32
27
 
33
28
  # Configuration accessor.
@@ -38,7 +33,7 @@ class USPSFlags
38
33
  # Configuration constructor.
39
34
  def self.configure
40
35
  yield(configuration) if block_given?
41
- self.ensure_directories
36
+ ensure_directories
42
37
  @configuration
43
38
  end
44
39
 
@@ -46,9 +41,9 @@ class USPSFlags
46
41
  #
47
42
  # @private
48
43
  def self.ensure_directories
49
- self.get_dir_configs
50
- self.prepare_dir_configs
51
- self.prepare_flags_dir
44
+ get_dir_configs
45
+ prepare_dir_configs
46
+ prepare_flags_dir
52
47
  ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
53
48
  end
54
49
 
@@ -56,12 +51,8 @@ class USPSFlags
56
51
  #
57
52
  # @private
58
53
  def self.get_dir_configs
59
- @dirs = USPSFlags.configuration.
60
- instance_variables.
61
- map(&:to_s).
62
- map { |v| v.match(/.*?_dir/) }.
63
- reject! { |v| v.nil? }.
64
- map(&:to_s)
54
+ @dirs = USPSFlags.configuration.instance_variables.map(&:to_s)
55
+ .map { |v| v.match(/.*?_dir/) }.compact.map(&:to_s)
65
56
  end
66
57
 
67
58
  # Ensures that directories exist (and are cleared, if configured).
@@ -98,14 +89,14 @@ class USPSFlags
98
89
  #
99
90
  # flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
100
91
  # flag.png #=> Generates PNG file at "/path/to/png/output.png"
101
- def initialize
102
- @type = nil
103
- @svg_file = nil
104
- @png_file = nil
105
- @scale = nil
106
- @field = nil
107
- @trim = nil
108
- yield self if block_given?
92
+ def initialize(options = {})
93
+ @type = options[:type]
94
+ @svg_file = options[:svg_file]
95
+ @png_file = options[:png_file]
96
+ @scale = options[:scale]
97
+ @field = options[:field]
98
+ @trim = options[:trim]
99
+ yield(self) if block_given?
109
100
  end
110
101
 
111
102
  # Constructor accessors.
@@ -122,8 +113,8 @@ class USPSFlags
122
113
  #
123
114
  # @return [String] Returns the SVG file output path, or the svg data if no path was specified.
124
115
  def svg
125
- svg = USPSFlags::Generate.svg(self.type, outfile: self.svg_file, scale: self.scale, field: self.field)
126
- (self.svg_file.nil? || self.svg_file == '') ? svg : self.svg_file
116
+ svg = USPSFlags::Generate.svg(type, outfile: svg_file, scale: scale, field: field)
117
+ svg_file.nil? || svg_file == '' ? svg : svg_file
127
118
  end
128
119
 
129
120
  # Generates the constructed file as PNG.
@@ -132,12 +123,12 @@ class USPSFlags
132
123
  #
133
124
  # @return [String] Returns the SVG file output path.
134
125
  def png
135
- raise USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.' if self.png_file.nil?
126
+ raise USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.' if png_file.nil?
136
127
 
137
- svg_file_storage = self.svg_file
128
+ svg_file_storage = svg_file
138
129
  self.svg_file = ''
139
- USPSFlags::Generate.png(self.svg, outfile: self.png_file, trim: self.trim)
130
+ USPSFlags::Generate.png(svg, outfile: png_file, trim: trim)
140
131
  self.svg_file = svg_file_storage
141
- self.png_file
132
+ png_file
142
133
  end
143
134
  end
@@ -1,108 +1,110 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # Container class for configuration values.
4
- class USPSFlags::Config
5
- BLUE ||= '#012169'
6
- RED ||= '#E4002B'
7
- GOLD ||= '#FFBF3F'
8
- OLD_GLORY_BLUE ||= '#041E42'
9
- OLD_GLORY_RED ||= '#BF0D3E'
4
+ class USPSFlags
5
+ class Config
6
+ BLUE ||= '#012169'.freeze
7
+ RED ||= '#E4002B'.freeze
8
+ GOLD ||= '#FFBF3F'.freeze
9
+ OLD_GLORY_BLUE ||= '#041E42'.freeze
10
+ OLD_GLORY_RED ||= '#BF0D3E'.freeze
10
11
 
11
- # Base measurements for most flags, before scaling
12
- BASE_FLY ||= 3072
13
- BASE_HOIST ||= BASE_FLY * 2 / 3
14
- FRACTION_SCALE ||= 85
12
+ # Base measurements for most flags, before scaling
13
+ BASE_FLY ||= 3072
14
+ BASE_HOIST ||= BASE_FLY * 2 / 3
15
+ FRACTION_SCALE ||= 85
15
16
 
16
- attr_accessor :flags_dir, :clear
17
+ attr_accessor :flags_dir, :clear
17
18
 
18
- # Configuration constructor
19
- #
20
- # @param [String] flag_dir The path to the flags directory.
21
- # @param [Boolean] clear Whether to clear out the specified flags_dir.
22
- def initialize
23
- get_defaults
24
- yield self if block_given?
25
- end
19
+ # Configuration constructor
20
+ #
21
+ # @param [String] flag_dir The path to the flags directory.
22
+ # @param [Boolean] clear Whether to clear out the specified flags_dir.
23
+ def initialize
24
+ get_defaults
25
+ yield self if block_given?
26
+ end
26
27
 
27
- # Base configuration values for trident insignia.
28
- #
29
- # All other values are derived from these, or directly from the constant sizes.
30
- #
31
- # @return [Hash] RThe configuration values for tridents.
32
- def trident
33
- {
34
- height: trident_heights, center_point: BASE_FLY / 2,
35
- width: USPSFlags::Config::BASE_FLY * 5 / 32, bar_width: bar_width,
36
- hash_width: USPSFlags::Config::BASE_FLY * 47 / 528
37
- }.merge(spikes_config).merge(delta_config).merge(circle_config)
38
- end
28
+ # Base configuration values for trident insignia.
29
+ #
30
+ # All other values are derived from these, or directly from the constant sizes.
31
+ #
32
+ # @return [Hash] RThe configuration values for tridents.
33
+ def trident
34
+ {
35
+ height: trident_heights, center_point: BASE_FLY / 2,
36
+ width: USPSFlags::Config::BASE_FLY * 5 / 32, bar_width: bar_width,
37
+ hash_width: USPSFlags::Config::BASE_FLY * 47 / 528
38
+ }.merge(spikes_config).merge(delta_config).merge(circle_config)
39
+ end
39
40
 
40
- # Height values for trident insignia.
41
- #
42
- # @return [Hash] The height values for tridents.
43
- def trident_heights
44
- {
45
- s: USPSFlags::Config::BASE_HOIST / 2,
46
- d: USPSFlags::Config::BASE_HOIST * 5 / 8,
47
- stf: USPSFlags::Config::BASE_HOIST * 3 / 4,
48
- n: USPSFlags::Config::BASE_HOIST * 3 / 4
49
- }
50
- end
41
+ # Height values for trident insignia.
42
+ #
43
+ # @return [Hash] The height values for tridents.
44
+ def trident_heights
45
+ {
46
+ s: USPSFlags::Config::BASE_HOIST / 2,
47
+ d: USPSFlags::Config::BASE_HOIST * 5 / 8,
48
+ stf: USPSFlags::Config::BASE_HOIST * 3 / 4,
49
+ n: USPSFlags::Config::BASE_HOIST * 3 / 4
50
+ }
51
+ end
51
52
 
52
- # Alias for the directory to store generated log files.
53
- #
54
- # @return [String] The current path to the logs directory.
55
- def log_path
56
- if defined?(::Rails)
57
- "#{::Rails.root}/log"
58
- else
59
- "#{USPSFlags.configuration.flags_dir}/log"
53
+ # Alias for the directory to store generated log files.
54
+ #
55
+ # @return [String] The current path to the logs directory.
56
+ def log_path
57
+ if defined?(::Rails)
58
+ "#{::Rails.root}/log"
59
+ else
60
+ "#{USPSFlags.configuration.flags_dir}/log"
61
+ end
60
62
  end
61
- end
62
63
 
63
- private
64
+ private
64
65
 
65
- def get_defaults
66
- @flags_dir = if defined?(::Rails)
67
- "#{::Rails.root}/app/assets/images/usps-flags"
68
- else
69
- "#{File.dirname(__dir__)}/output"
66
+ def get_defaults
67
+ @flags_dir = if defined?(::Rails)
68
+ "#{::Rails.root}/app/assets/images/usps-flags"
69
+ else
70
+ "#{File.dirname(__dir__)}/output"
71
+ end
72
+ @use_larger_tridents = true
73
+ @clear = false
70
74
  end
71
- @use_larger_tridents = true
72
- @clear = false
73
- end
74
75
 
75
- def center_point_height
76
- USPSFlags::Config::BASE_FLY / 48 * 23 / 8
77
- end
76
+ def center_point_height
77
+ USPSFlags::Config::BASE_FLY / 48 * 23 / 8
78
+ end
78
79
 
79
- def side_point_height
80
- USPSFlags::Config::BASE_FLY / 48 * 21 / 8
81
- end
80
+ def side_point_height
81
+ USPSFlags::Config::BASE_FLY / 48 * 21 / 8
82
+ end
82
83
 
83
- def bar_width
84
- USPSFlags::Config::BASE_FLY / 48 * 5 / 4
85
- end
84
+ def bar_width
85
+ USPSFlags::Config::BASE_FLY / 48 * 5 / 4
86
+ end
86
87
 
87
- def spikes_config
88
- {
89
- center_point_height: center_point_height, side_point_height: side_point_height,
90
- main_point_barb: USPSFlags::Config::BASE_HOIST / 82,
91
- crossbar_from_top: USPSFlags::Config::BASE_HOIST / 4 + bar_width / 5,
92
- side_spike_height: USPSFlags::Config::BASE_HOIST / 4 - side_point_height - bar_width * 3 / 5
93
- }
94
- end
88
+ def spikes_config
89
+ {
90
+ center_point_height: center_point_height, side_point_height: side_point_height,
91
+ main_point_barb: USPSFlags::Config::BASE_HOIST / 82,
92
+ crossbar_from_top: USPSFlags::Config::BASE_HOIST / 4 + bar_width / 5,
93
+ side_spike_height: USPSFlags::Config::BASE_HOIST / 4 - side_point_height - bar_width * 3 / 5
94
+ }
95
+ end
95
96
 
96
- def delta_config
97
- {
98
- delta_height: USPSFlags::Config::BASE_FLY * 33 / 240, delta_gap_height: USPSFlags::Config::BASE_FLY / 16,
99
- delta_gap_width: bar_width * 5 / 4, delta_width: USPSFlags::Config::BASE_FLY * 43 / 768,
100
- delta_from_bottom: USPSFlags::Config::BASE_HOIST * 10 / 64, delta_gap_scale: 0.40,
101
- delta_gap_x: USPSFlags::Config::BASE_HOIST * 144 / 128, delta_gap_y: USPSFlags::Config::BASE_HOIST * 221 / 256
102
- }
103
- end
97
+ def delta_config
98
+ {
99
+ delta_height: USPSFlags::Config::BASE_FLY * 33 / 240, delta_gap_height: USPSFlags::Config::BASE_FLY / 16,
100
+ delta_gap_width: bar_width * 5 / 4, delta_width: USPSFlags::Config::BASE_FLY * 43 / 768,
101
+ delta_from_bottom: USPSFlags::Config::BASE_HOIST * 10 / 64, delta_gap_scale: 0.40,
102
+ delta_gap_x: USPSFlags::Config::BASE_HOIST * 144 / 128, delta_gap_y: USPSFlags::Config::BASE_HOIST * 221 / 256
103
+ }
104
+ end
104
105
 
105
- def circle_config
106
- { circle_height_adj: USPSFlags::Config::BASE_FLY / 800 }
106
+ def circle_config
107
+ { circle_height_adj: USPSFlags::Config::BASE_FLY / 800 }
108
+ end
107
109
  end
108
110
  end