usps_flags 0.4.1 → 0.5.0

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.
@@ -11,41 +11,10 @@ class USPSFlags::Helpers::Builders
11
11
  # This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
12
12
  # @private
13
13
  def grid(width: USPSFlags::Config::BASE_FLY, height: USPSFlags::Config::BASE_HOIST)
14
- <<~SVG
15
- <circle cx="0" cy="0" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
16
- <circle cx="#{width}" cy="0" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
17
- <circle cx="#{width}" cy="#{height}" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
18
- <circle cx="0" cy="#{height}" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
19
-
20
- <circle cx="#{width * 1 / 4}" cy="#{height / 2}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
21
- <circle cx="#{width * 3 / 4}" cy="#{height / 2}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
22
-
23
- <circle cx="#{width / 2}" cy="#{height * 1 / 4}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
24
- <circle cx="#{width / 2}" cy="#{height / 2}" r="#{width / 60}" fill="#000000" fill-opacity="0.4" />
25
- <circle cx="#{width / 2}" cy="#{height / 2}" r="#{width / 75}" fill="#CCCCCC" fill-opacity="0.4" />
26
- <circle cx="#{width / 2}" cy="#{height / 2}" r="#{width / 100}" fill="#000000" fill-opacity="0.4" />
27
- <circle cx="#{width / 2}" cy="#{height * 3 / 4}" r="#{width / 60}" fill="#999999" fill-opacity="0.4" />
28
-
29
- <line x1="0" y1="0" x2="#{width}" y2="0" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
30
- <line x1="0" y1="#{height * 1 / 4}" x2="#{width}" y2="#{height * 1 / 4}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
31
- <line x1="0" y1="#{height / 2}" x2="#{width}" y2="#{height / 2}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
32
- <line x1="0" y1="#{height * 3 / 4}" x2="#{width}" y2="#{height * 3 / 4}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
33
- <line x1="0" y1="#{height}" x2="#{width}" y2="#{height}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
34
-
35
- <line y1="0" x1="0" y2="#{height}" x2="0" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
36
- <line y1="0" x1="#{width * 1 / 6}" y2="#{height}" x2="#{width * 1 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
37
- <line y1="0" x1="#{width * 2 / 6}" y2="#{height}" x2="#{width * 2 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
38
- <line y1="0" x1="#{width * 3 / 6}" y2="#{height}" x2="#{width * 3 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
39
- <line y1="0" x1="#{width * 4 / 6}" y2="#{height}" x2="#{width * 4 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
40
- <line y1="0" x1="#{width * 5 / 6}" y2="#{height}" x2="#{width * 5 / 6}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
41
- <line y1="0" x1="#{width}" y2="#{height}" x2="#{width}" stroke="#333333" stroke-width="#{width / 600}" stroke-opacity="0.5" />
42
-
43
- <line x1="#{width / 2}" y1="#{height * 1 / 4}" x2="#{width * 3 / 4}" y2="#{height / 2}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
44
- <line x1="#{width * 3 / 4}" y1="#{height / 2}" x2="#{width / 2}" y2="#{height * 3 / 4}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
45
- <line x1="#{width / 2}" y1="#{height * 3 / 4}" x2="#{width * 1 / 4}" y2="#{height / 2}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
46
- <line x1="#{width * 1 / 4}" y1="#{height / 2}" x2="#{width / 2}" y2="#{height * 1 / 4}" stroke="#999999" stroke-width="#{width / 600}" stroke-opacity="0.5" />
47
-
48
- SVG
14
+ @width = width
15
+ @height = height
16
+ @stroke_width = @width / 600
17
+ "#{circles}#{horizontal_lines}#{vertical_lines}#{diagonal_lines}"
49
18
  end
50
19
 
51
20
  # Displays an overlay indicator of concentric circles and radiating lines.
@@ -69,5 +38,71 @@ class USPSFlags::Helpers::Builders
69
38
  <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY / 30}" height="#{USPSFlags::Config::BASE_FLY / 30}" fill="#333333" fill-opacity="0.6" />
70
39
  SVG
71
40
  end
41
+
42
+ private
43
+
44
+ def circles
45
+ <<~SVG
46
+ #{pos_circle(0, 0)}
47
+ #{pos_circle(@width, 0)}
48
+ #{pos_circle(@width, @height)}
49
+ #{pos_circle(0, @height)}
50
+ <circle cx="#{@width * 1 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
51
+ <circle cx="#{@width * 3 / 4}" cy="#{@height / 2}" r="#{@width / 60}" fill="#999999" fill-opacity="0.4" />
52
+ #{radial_circles}
53
+ SVG
54
+ end
55
+
56
+ def radial_circles
57
+ <<~SVG
58
+ #{radial_circle(1, @width / 60)}
59
+ #{radial_circle(2, @width / 60)}
60
+ #{radial_circle(2, @width / 75)}
61
+ #{radial_circle(2, @width / 100)}
62
+ #{radial_circle(3, @width / 60)}
63
+ SVG
64
+ end
65
+
66
+ def pos_circle(cx, cy)
67
+ <<~SVG
68
+ <circle cx="#{cx}" cy="#{cy}" r="#{@width / 60}" fill="#000000" fill-opacity="0.4" />
69
+ SVG
70
+ end
71
+
72
+ def radial_circle(index, radius)
73
+ <<~SVG
74
+ <circle cx="#{@width / 2}" cy="#{@height * index / 4}" r="#{radius}" fill="#999999" fill-opacity="0.4" />
75
+ SVG
76
+ end
77
+
78
+ def horizontal_lines
79
+ (0..4).map { |index| horizontal_line(index) }.join
80
+ end
81
+
82
+ def horizontal_line(index)
83
+ <<~SVG
84
+ <line x1="0" y1="#{@height * index / 4}" x2="#{@width}" y2="#{@height * index / 4}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
85
+ SVG
86
+ end
87
+
88
+ def vertical_lines
89
+ (0..6).map { |index| vertical_line(index) }.join
90
+ end
91
+
92
+ def vertical_line(index)
93
+ <<~SVG
94
+ <line y1="0" x1="#{@width * index / 6}" y2="#{@height}" x2="#{@width * index / 6}" stroke="#333333" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
95
+ SVG
96
+ end
97
+
98
+ def diagonal_lines
99
+ "#{diagonal_line(2, 1, 3, 2)}#{diagonal_line(3, 2, 2, 3)}#{diagonal_line(2, 3, 1, 2)}#{diagonal_line(1, 2, 2, 1)}"
100
+ end
101
+
102
+ def diagonal_line(a, b, c, d)
103
+ <<~SVG
104
+ <line x1="#{@width * a / 4}" y1="#{@height * b / 4}" x2="#{@width * c / 4}" y2="#{@height * d / 4}" stroke="#999999" stroke-width="#{@stroke_width}" stroke-opacity="0.5" />
105
+ SVG
106
+ end
72
107
  end
73
108
  end
@@ -10,49 +10,99 @@ class USPSFlags::Helpers::SpecArrows
10
10
  #
11
11
  # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
12
12
  # @private
13
- def vertical(x, top, bottom, pointer_top = nil, pointer_bottom = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / 120), label_offset_y: 0, label_align: 'left')
14
- load_common_config(fly)
15
- label, label_fraction = get_labels(bottom, top)
16
- svg = ''
17
-
18
- svg << arrow_pointer(x, pointer_top, top, top) unless pointer_top.nil?
19
- svg << arrow_pointer(x, pointer_bottom, bottom, bottom) unless pointer_bottom.nil?
13
+ def vertical(x, top, bottom, **options)
14
+ options = defaults.merge(options)
20
15
 
21
- svg << <<~SVG
22
- <path d="M#{x} #{top} l #{@arrow_size} #{@arrow_size} M#{x} #{top} l -#{@arrow_size} #{@arrow_size} M#{x} #{top} l 0 #{bottom - top} l #{@arrow_size} -#{@arrow_size} M#{x} #{bottom} l -#{@arrow_size} -#{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
23
- <g>
24
- <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
25
- <text x="#{x + label_offset}" y="#{(top + bottom) / 2 + (USPSFlags::Config::BASE_HOIST / 150) + label_offset_y}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{label_align}">#{label} <tspan>#{label_fraction}</tspan> #{unit}</text>
26
- </g>
27
- SVG
16
+ load_common_config(options[:fly])
17
+ label, label_fraction = get_labels(bottom, top)
18
+ options = options.merge(x: x, top: top, bottom: bottom, label: label, label_fraction: label_fraction)
28
19
 
29
- svg
20
+ vertical_svg_group(options)
30
21
  end
31
22
 
32
23
  # Creates a horizontal arrow for the trident spec sheet.
33
24
  #
34
25
  # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
35
26
  # @private
36
- def horizontal(y, left, right, pointer_left = nil, pointer_right = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / 45), label_offset_x: 0, label_align: 'middle')
37
- load_common_config(fly)
27
+ def horizontal(y, left, right, **options)
28
+ options = defaults(:h).merge(options)
29
+
30
+ load_common_config(options[:fly])
38
31
  label, label_fraction = get_labels(right, left)
39
- svg = ''
32
+ options = options.merge(y: y, left: left, right: right, label: label, label_fraction: label_fraction)
40
33
 
41
- svg << arrow_pointer(left, left, pointer_left, y) unless pointer_left.nil?
42
- svg << arrow_pointer(right, right, y, pointer_right) unless pointer_right.nil?
34
+ horizontal_svg_group(options)
35
+ end
43
36
 
44
- svg << <<~SVG
45
- <path d="M#{left} #{y} l #{@arrow_size} #{@arrow_size} M#{left} #{y} l #{@arrow_size} -#{@arrow_size} M#{left} #{y} l #{right - left} 0 l -#{@arrow_size} -#{@arrow_size} M#{right} #{y} l -#{@arrow_size} #{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
37
+ private
38
+
39
+ def defaults(mode = :v)
40
+ {
41
+ pointer_top: nil, pointer_bottom: nil, pointer_left: nil, pointer_right: nil, fly: nil,
42
+ unit: nil, label_offset: (USPSFlags::Config::BASE_FLY / (mode == :v ? 120 : 45)),
43
+ label_offset_x: 0, label_offset_y: 0, label_align: (mode == :v ? 'left' : 'middle')
44
+ }
45
+ end
46
+
47
+ def vertical_svg_group(options)
48
+ svg = +''
49
+ svg << arrow_pointer(options) unless options[:pointer_top].nil?
50
+ svg << arrow_pointer(options) unless options[:pointer_bottom].nil?
51
+ svg << vertical_svg(options)
52
+ svg
53
+ end
54
+
55
+ def vertical_svg(options)
56
+ <<~SVG
57
+ <path d="#{vertical_svg_path(options)}" fill="none" />
46
58
  <g>
47
59
  <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
48
- <text x="#{(left + right) / 2 + label_offset_x}" y="#{y + label_offset}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{label_align}">#{label} <tspan>#{label_fraction}</tspan> #{unit}</text>
60
+ #{vertical_svg_text(options)}
49
61
  </g>
50
62
  SVG
63
+ end
64
+
65
+ def vertical_svg_path(options)
66
+ <<~SVG
67
+ M#{options[:x]} #{options[:top]} l #{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l -#{@arrow_size} #{@arrow_size} M#{options[:x]} #{options[:top]} l 0 #{options[:bottom] - options[:top]} l #{@arrow_size} -#{@arrow_size} M#{options[:x]} #{options[:bottom]} l -#{@arrow_size} -#{@arrow_size}" stroke="#{@color}" stroke-width="#{@stroke_width}
68
+ SVG
69
+ end
70
+
71
+ def vertical_svg_text(options)
72
+ <<~SVG
73
+ <text x="#{options[:x] + options[:label_offset]}" y="#{(options[:top] + options[:bottom]) / 2 + (USPSFlags::Config::BASE_HOIST / 150) + options[:label_offset_y]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
74
+ SVG
75
+ end
51
76
 
77
+ def horizontal_svg_group(options)
78
+ svg = +''
79
+ svg << arrow_pointer(options) unless options[:pointer_left].nil?
80
+ svg << arrow_pointer(options) unless options[:pointer_right].nil?
81
+ svg << horizontal_svg(options)
52
82
  svg
53
83
  end
54
84
 
55
- private
85
+ def horizontal_svg(options)
86
+ <<~SVG
87
+ <path d="#{horizontal_svg_path(options)}" stroke="#{@color}" stroke-width="#{@stroke_width}" fill="none" />
88
+ <g>
89
+ <style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
90
+ #{horizontal_svg_text(options)}
91
+ </g>
92
+ SVG
93
+ end
94
+
95
+ def horizontal_svg_path(options)
96
+ <<~SVG
97
+ M#{options[:left]} #{options[:y]} l #{@arrow_size} #{@arrow_size} M#{options[:left]} #{options[:y]} l #{@arrow_size} -#{@arrow_size} M#{options[:left]} #{options[:y]} l #{options[:right] - options[:left]} 0 l -#{@arrow_size} -#{@arrow_size} M#{options[:right]} #{options[:y]} l -#{@arrow_size} #{@arrow_size}
98
+ SVG
99
+ end
100
+
101
+ def horizontal_svg_text(options)
102
+ <<~SVG
103
+ <text x="#{(options[:left] + options[:right]) / 2 + options[:label_offset_x]}" y="#{options[:y] + options[:label_offset]}" font-family="sans-serif" font-size="#{@font_size}px" fill="#041E42" text-anchor="#{options[:label_align]}">#{options[:label]} <tspan>#{options[:label_fraction]}</tspan> #{options[:unit]}</text>
104
+ SVG
105
+ end
56
106
 
57
107
  def load_common_config(fly)
58
108
  @color = '#CCCCCC'
@@ -63,9 +113,9 @@ class USPSFlags::Helpers::SpecArrows
63
113
  @fly = fly || USPSFlags::Config::BASE_FLY
64
114
  end
65
115
 
66
- def arrow_pointer(x1, x2, y1, y2)
116
+ def arrow_pointer(options)
67
117
  <<~SVG
68
- <line x1="#{x1}" y1="#{y1}" x2="#{x2}" y2="#{y2}" stroke="#{@color}" stroke-width="#{@stroke_width}" stroke-dasharray="#{@stroke_dash}" />
118
+ <line x1="#{options[:x1]}" y1="#{options[:y1]}" x2="#{options[:x2]}" y2="#{options[:y2]}" stroke="#{@color}" stroke-width="#{@stroke_width}" stroke-dasharray="#{@stroke_dash}" />
69
119
  SVG
70
120
  end
71
121
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: false
2
+
3
+ # Valid flag configuration for USPSFlags::Helpers.
4
+ #
5
+ # These methods should never need to be called directly.
6
+ # @private
7
+ module USPSFlags::Helpers::ValidFlags
8
+ class << self
9
+ def load_valid_flags
10
+ @squadron_past = %w[PLTC PC]
11
+ @squadron_elected = %w[1LT LTC CDR]
12
+ @squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT]
13
+ @district_past = %w[PDLTC PDC]
14
+ @district_elected = %w[D1LT DLTC DC]
15
+ @district_swallowtail = %w[DLT DAIDE DFLT]
16
+ @national_past = %w[PSTFC PRC PVC PCC]
17
+ @national_elected = %w[STFC RC VC CC]
18
+ @national_swallowtail = %w[NAIDE NFLT]
19
+ end
20
+
21
+ def load_special_flags
22
+ @special = %w[CRUISE OIC ENSIGN] # WHEEL
23
+ @us = %w[US]
24
+ end
25
+
26
+ def load_valid_flag_groups
27
+ @past = @squadron_past + @district_past + @national_past
28
+ @squadron = @squadron_past + @squadron_elected + @squadron_swallowtail
29
+ @district = @district_past + @district_elected + @district_swallowtail
30
+ @national = @national_past + @national_elected + @national_swallowtail
31
+ @officer = @squadron + @district + @national
32
+ end
33
+
34
+ def valid_flags_for(type)
35
+ {
36
+ special: @special, us: @us, bridge: bridge_flags, command: command_flags,
37
+ squadron: @squadron, district: @district, national: @national, past: @past,
38
+ all: @officer + @special + @us, officer: @officer, insignia: @officer - @past,
39
+ swallowtail: @past + @squadron_swallowtail + @district_swallowtail + @national_swallowtail
40
+ }[type]
41
+ end
42
+
43
+ def bridge_flags
44
+ @squadron_elected.last(2) + @district_elected.last(2) + @national_elected.last(2) +
45
+ @squadron_past.last(2) + @district_past.last(2) + @national_past.last(2)
46
+ end
47
+
48
+ def command_flags
49
+ [
50
+ @squadron_elected.last, @district_elected.last, @national_elected.last,
51
+ @squadron_past.last, @district_past.last, @national_past.last
52
+ ]
53
+ end
54
+ end
55
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Container class for helper methods.
4
4
  class USPSFlags::Helpers
5
+ require 'usps_flags/helpers/valid_flags'
6
+
5
7
  class << self
6
8
  # Valid options for flag generation.
7
9
  #
@@ -16,8 +18,10 @@ class USPSFlags::Helpers
16
18
  # @option type [Symbol] :us US flag
17
19
  # @return [Array] Valid options for flag generation (based on the provided type).
18
20
  def valid_flags(type = :all)
19
- load_valid_flags
20
- valid_flags_for(type)
21
+ USPSFlags::Helpers::ValidFlags.load_valid_flags
22
+ USPSFlags::Helpers::ValidFlags.load_special_flags
23
+ USPSFlags::Helpers::ValidFlags.load_valid_flag_groups
24
+ USPSFlags::Helpers::ValidFlags.valid_flags_for(type)
21
25
  end
22
26
 
23
27
  # Resizes and saves a PNG image.
@@ -34,13 +38,7 @@ class USPSFlags::Helpers
34
38
  raise USPSFlags::Errors::PNGConversionError if outfile.nil? && size_key.nil?
35
39
 
36
40
  output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
37
- MiniMagick::Tool::Convert.new do |convert|
38
- convert << '-background' << 'none'
39
- convert << '-format' << 'png'
40
- convert << '-resize' << "#{size}"
41
- convert << png_file
42
- convert << output_file_name
43
- end
41
+ resize_convert(size, png_file, output_file_name)
44
42
  end
45
43
 
46
44
  # Gets the maximum length among valid flags.
@@ -142,49 +140,14 @@ class USPSFlags::Helpers
142
140
 
143
141
  private
144
142
 
145
- def load_valid_flags
146
- @squadron_past = %w[PLTC PC]
147
- @squadron_elected = %w[1LT LTC CDR]
148
- @squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT]
149
- @district_past = %w[PDLTC PDC]
150
- @district_elected = %w[D1LT DLTC DC]
151
- @district_swallowtail = %w[DLT DAIDE DFLT]
152
- @national_past = %w[PSTFC PRC PVC PCC]
153
- @national_elected = %w[STFC RC VC CC]
154
- @national_swallowtail = %w[NAIDE NFLT]
155
- @special = %w[CRUISE OIC ENSIGN] # WHEEL
156
- @us = %w[US]
157
-
158
- @past = @squadron_past + @district_past + @national_past
159
- @squadron = @squadron_past + @squadron_elected + @squadron_swallowtail
160
- @district = @district_past + @district_elected + @district_swallowtail
161
- @national = @national_past + @national_elected + @national_swallowtail
162
- @officer = @squadron + @district + @national
163
- end
164
-
165
- def valid_flags_for(type)
166
- {
167
- special: @special,
168
- us: @us,
169
-
170
- squadron: @squadron,
171
- district: @district,
172
- national: @national,
173
- past: @past,
174
-
175
- all: @officer + @special + @us,
176
- officer: @officer,
177
- insignia: @officer - @past,
178
- swallowtail: @past + @squadron_swallowtail + @district_swallowtail + @national_swallowtail,
179
-
180
- bridge: @squadron_elected.last(2) + @squadron_past.last(2) +
181
- @district_elected.last(2) + @district_past.last(2) +
182
- @national_elected.last(2) + @national_past.last(2),
183
-
184
- command: [@squadron_elected.last, @squadron_past.last,
185
- @district_elected.last, @district_past.last,
186
- @national_elected.last, @national_past.last]
187
- }[type]
143
+ def resize_convert(size, png_file, output_file_name)
144
+ MiniMagick::Tool::Convert.new do |convert|
145
+ convert << '-background' << 'none'
146
+ convert << '-format' << 'png'
147
+ convert << '-resize' << "#{size}"
148
+ convert << png_file
149
+ convert << output_file_name
150
+ end
188
151
  end
189
152
 
190
153
  def flag_style(rank)
data/spec/spec_helper.rb CHANGED
@@ -4,12 +4,10 @@ require 'bundler/setup'
4
4
  Bundler.setup
5
5
  require 'simplecov'
6
6
  SimpleCov.start
7
+ SimpleCov.minimum_coverage(100)
7
8
 
8
9
  require 'usps_flags'
9
10
 
10
- # Some specs contain examples that check for the custom examples from USPSFlags::Errors
11
- RSpec::Expectations.configuration.on_potential_false_positives = :nothing
12
-
13
11
  RSpec.configure do |config|
14
12
  config.before(:suite) do
15
13
  $tmp_flags_dir = 'tmp/flags'
@@ -4,7 +4,9 @@ require 'spec_helper'
4
4
 
5
5
  describe USPSFlags::Core do
6
6
  describe 'trident_spec' do
7
- ['Field', 'Specification Heading Information', 'Short Trident', 'Delta Trident', 'Circle Trident', 'Long Trident'].each do |section|
7
+ [
8
+ 'Field', 'Specification Heading Information', 'Short Trident', 'Delta Trident', 'Circle Trident', 'Long Trident'
9
+ ].each do |section|
8
10
  it "should contain the #{section} section" do
9
11
  expect(USPSFlags::Core.trident_spec).to include("<!-- #{section} -->")
10
12
  end
@@ -76,28 +78,24 @@ describe USPSFlags::Core do
76
78
  expect(USPSFlags::Core.field(style: :past, color: :blue)).to eql(
77
79
  <<~SVG
78
80
  <g transform="translate(2, 1)">
79
- <path d="M 0 5
80
- l #{@fly / 2} #{@hoist * 1 / 12}
81
- l 0 #{@hoist * 10 / 12}
82
- l -#{@fly / 2} #{@hoist * 1 / 12}
83
- " fill="#{@blue}" />
84
- <path d="M #{@fly / 2} #{@hoist * 1 / 12}
85
- l #{@fly / 4} #{@hoist * 1 / 24}
86
- l 0 #{@hoist * 9 / 12}
87
- l -#{@fly / 4} #{@hoist * 1 / 24}
88
- " fill="#FFFFFF" />
89
- <path d="M #{@fly * 3 / 4} #{@hoist * 3 / 24}
90
- l #{@fly / 4} #{@hoist * 1 / 24}
91
- l -#{@fly / 5} #{@hoist / 3}
92
- l #{@fly / 5} #{@hoist / 3}
93
- l -#{@fly / 4} #{@hoist * 1 / 24}
94
- " fill="#{@red}" />
95
- <path d="M 0 0
96
- l #{@fly} #{@hoist / 6}
97
- l -#{@fly / 5} #{@hoist / 3}
98
- l #{@fly / 5} #{@hoist / 3}
99
- l -#{@fly} #{@hoist / 6} z
100
- " fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
81
+ <path d="M 0 5 l #{@fly / 2} #{@hoist * 1 / 12}
82
+ l 0 #{@hoist * 10 / 12}
83
+ l -#{@fly / 2} #{@hoist * 1 / 12}
84
+ " fill="#{@blue}" />
85
+ <path d="M #{@fly / 2} #{@hoist * 1 / 12} l #{@fly / 4} #{@hoist * 1 / 24}
86
+ l 0 #{@hoist * 9 / 12}
87
+ l -#{@fly / 4} #{@hoist * 1 / 24}
88
+ " fill="#FFFFFF" />
89
+ <path d="M #{@fly * 3 / 4} #{@hoist * 3 / 24} l #{@fly / 4} #{@hoist * 1 / 24}
90
+ l -#{@fly / 5} #{@hoist / 3}
91
+ l #{@fly / 5} #{@hoist / 3}
92
+ l -#{@fly / 4} #{@hoist * 1 / 24}
93
+ " fill="#{@red}" />
94
+ <path d="M 0 0 l #{@fly} #{@hoist / 6}
95
+ l -#{@fly / 5} #{@hoist / 3}
96
+ l #{@fly / 5} #{@hoist / 3}
97
+ l -#{@fly} #{@hoist / 6}
98
+ z" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
101
99
  </g>
102
100
  SVG
103
101
  )
@@ -110,11 +108,15 @@ describe USPSFlags::Core do
110
108
  end
111
109
 
112
110
  it 'should correctly generate a delta trident' do
113
- expect(USPSFlags::Core.trident(:d)).to include("<g mask=\"url(#delta-mask)\"><path d=\"M #{@fly / 2} #{@hoist * 3 / 16}\n")
111
+ expect(USPSFlags::Core.trident(:d)).to include(
112
+ "<g mask=\"url(#delta-mask)\"><path d=\"M #{@fly / 2} #{@hoist * 3 / 16}\n"
113
+ )
114
114
  end
115
115
 
116
116
  it 'should correctly generate a circle trident' do
117
- expect(USPSFlags::Core.trident(:stf)).to include("<g mask=\"url(#circle-mask-for-main-spike)\"><path d=\"M #{@fly / 2} #{@hoist / 8}\n")
117
+ expect(USPSFlags::Core.trident(:stf)).to include(
118
+ "<g mask=\"url(#circle-mask-for-main-spike)\"><path d=\"M #{@fly / 2} #{@hoist / 8}\n"
119
+ )
118
120
  end
119
121
 
120
122
  it 'should correctly generate a long trident' do
@@ -75,7 +75,9 @@ describe USPSFlags::Generate do
75
75
  end
76
76
 
77
77
  it 'should generate the trident specification sheet with a scaled border' do
78
- expect(USPSFlags::Generate.spec(outfile: '', scaled_border: true)).to include('<title>USPS Trident Specifications</title>')
78
+ expect(USPSFlags::Generate.spec(outfile: '', scaled_border: true)).to include(
79
+ '<title>USPS Trident Specifications</title>'
80
+ )
79
81
  end
80
82
 
81
83
  it 'should generate the trident specification sheet with a fractional field size' do
@@ -101,7 +103,7 @@ describe USPSFlags::Generate do
101
103
  end
102
104
 
103
105
  it 'should not raise PNGGenerationError when correctly configured' do
104
- expect { USPSFlags::Generate.png(@svg, outfile: 'lib/output/PNG/LTC.png') }.to_not raise_error(USPSFlags::Errors::PNGGenerationError)
106
+ expect { USPSFlags::Generate.png(@svg, outfile: 'lib/output/PNG/LTC.png') }.to_not raise_error
105
107
  end
106
108
  end
107
109
 
@@ -115,7 +117,8 @@ describe USPSFlags::Generate do
115
117
  describe 'static files errors' do
116
118
  it 'should raise USPSFlags::Errors::StaticFilesGenerationError when not given any true arguments' do
117
119
  expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: false) }.to raise_error(
118
- USPSFlags::Errors::StaticFilesGenerationError, 'At least one argument switch must be true out of [svg, png, zips, reset].'
120
+ USPSFlags::Errors::StaticFilesGenerationError,
121
+ 'At least one argument switch must be true out of [svg, png, zips, reset].'
119
122
  )
120
123
  end
121
124
 
@@ -133,7 +136,10 @@ describe USPSFlags::Generate do
133
136
 
134
137
  @svg_flag, @png_flag = USPSFlags::Helpers.valid_flags(:officer).sample(2)
135
138
  @svg_ins_flag, @png_ins_flag, @thb_flag = USPSFlags::Helpers.valid_flags(:insignia).sample(3)
136
- puts "\nSelected test flags: ", " Sf: #{@svg_flag}", " Si: #{@svg_ins_flag}", " Pf: #{@png_flag}", " Pi: #{@png_ins_flag}", " Pt: #{@thb_flag}"
139
+ puts(
140
+ "\nSelected test flags: ", " Sf: #{@svg_flag}", " Si: #{@svg_ins_flag}", " Pf: #{@png_flag}",
141
+ " Pi: #{@png_ins_flag}", " Pt: #{@thb_flag}"
142
+ )
137
143
 
138
144
  ::FileUtils.rm_rf(USPSFlags.configuration.flags_dir)
139
145
  USPSFlags.prepare_flags_dir
@@ -141,13 +147,21 @@ describe USPSFlags::Generate do
141
147
  USPSFlags::Generate.svg(@svg_flag, outfile: "#{svg_dir}/#{@svg_flag}.svg")
142
148
  USPSFlags::Generate.svg(@svg_ins_flag, field: false, outfile: "#{svg_dir}/insignia/#{@svg_ins_flag}.svg")
143
149
  USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_flag, outfile: ''), outfile: "#{png_dir}/#{@png_flag}.png")
144
- USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_ins_flag, field: false, outfile: ''), trim: true, outfile: "#{png_dir}/insignia/#{@png_ins_flag}.png")
145
- USPSFlags::Generate.png(USPSFlags::Generate.svg(@thb_flag, field: false, outfile: ''), trim: true, outfile: "#{png_dir}/insignia/#{@thb_flag}.png")
146
- USPSFlags::Helpers.resize_png("#{png_dir}/insignia/#{@thb_flag}.png", file: "insignia/#{@thb_flag}", size: 150, size_key: 'thumb')
150
+ USPSFlags::Generate.png(
151
+ USPSFlags::Generate.svg(@png_ins_flag, field: false, outfile: ''),
152
+ trim: true, outfile: "#{png_dir}/insignia/#{@png_ins_flag}.png"
153
+ )
154
+ USPSFlags::Generate.png(
155
+ USPSFlags::Generate.svg(@thb_flag, field: false, outfile: ''),
156
+ trim: true, outfile: "#{png_dir}/insignia/#{@thb_flag}.png"
157
+ )
158
+ USPSFlags::Helpers.resize_png(
159
+ "#{png_dir}/insignia/#{@thb_flag}.png", file: "insignia/#{@thb_flag}", size: 150, size_key: 'thumb'
160
+ )
147
161
  end
148
162
 
149
163
  it 'should not raise an error while generating all static files' do
150
- expect { USPSFlags::Generate.all(reset: false) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError)
164
+ expect { USPSFlags::Generate.all(reset: false) }.to_not raise_error
151
165
  end
152
166
 
153
167
  describe 'generation logs' do
@@ -217,11 +231,11 @@ describe USPSFlags::Generate do
217
231
  end
218
232
 
219
233
  it 'should not raise an error while clearing all static files' do
220
- expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: true) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError)
234
+ expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: true) }.to_not raise_error
221
235
  end
222
236
 
223
237
  it 'should not raise an error while generating zip files' do
224
- expect { USPSFlags::Generate.zips }.to_not raise_error # (USPSFlags::Errors::ZipGenerationError)
238
+ expect { USPSFlags::Generate.zips }.to_not raise_error
225
239
  end
226
240
  end
227
241
  end
@@ -16,17 +16,24 @@ describe USPSFlags::Helpers do
16
16
  end
17
17
 
18
18
  it 'should correctly generate the grid helper' do
19
- expect(USPSFlags::Helpers::Builders.grid).to include("<circle cx=\"0\" cy=\"0\" r=\"#{USPSFlags::Config::BASE_FLY / 60}\" fill=\"#000000\" fill-opacity=\"0.4\" />")
19
+ expect(USPSFlags::Helpers::Builders.grid).to include(
20
+ "<circle cx=\"0\" cy=\"0\" r=\"#{USPSFlags::Config::BASE_FLY / 60}\" fill=\"#000000\" fill-opacity=\"0.4\" />"
21
+ )
20
22
  end
21
23
 
22
24
  it 'should correctly generate the locator helper' do
23
- expect(USPSFlags::Helpers::Builders.locator).to include("<rect x=\"0\" y=\"0\" width=\"#{USPSFlags::Config::BASE_FLY / 30}\" height=\"#{USPSFlags::Config::BASE_FLY / 30}\" fill=\"#333333\" fill-opacity=\"0.6\" />")
25
+ expect(USPSFlags::Helpers::Builders.locator).to include(
26
+ "<rect x=\"0\" y=\"0\" width=\"#{USPSFlags::Config::BASE_FLY / 30}\" " \
27
+ "height=\"#{USPSFlags::Config::BASE_FLY / 30}\" fill=\"#333333\" fill-opacity=\"0.6\" />"
28
+ )
24
29
  end
25
30
  end
26
31
 
27
32
  describe 'resize_png' do
28
33
  it 'should raise USPSFlags::Errors::PNGConversionError with invalid parameters' do
29
- expect { USPSFlags::Helpers.resize_png('path/to/image.png', size: 100, size_key: 'thumb') }.to raise_error(USPSFlags::Errors::PNGConversionError)
34
+ expect do
35
+ USPSFlags::Helpers.resize_png('path/to/image.png', size: 100, size_key: 'thumb')
36
+ end.to raise_error(USPSFlags::Errors::PNGConversionError)
30
37
  end
31
38
  end
32
39
  end
@@ -16,8 +16,7 @@ describe USPSFlags do
16
16
  @valid_body = <<~SVG
17
17
  <desc id="trademark-desc">This image is a registered trademark of United States Power Squadrons.</desc>
18
18
  <desc id="trademark-link">https://www.usps.org/images/secretary/itcom/trademark.pdf</desc>
19
- </metadata>
20
- <g transform="translate(-512)">
19
+ </metadata><g transform="translate(-512)">
21
20
  <path d="M 1536 512
22
21
  l 80 184
23
22
  l -40 -24
@@ -143,7 +142,9 @@ describe USPSFlags do
143
142
 
144
143
  describe 'png' do
145
144
  it 'should raise PNGGenerationError without png_file set' do
146
- expect { @flag.png }.to raise_error(USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.')
145
+ expect { @flag.png }.to raise_error(
146
+ USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.'
147
+ )
147
148
  end
148
149
 
149
150
  context 'with png_file set' do
@@ -153,7 +154,7 @@ describe USPSFlags do
153
154
  end
154
155
 
155
156
  it 'should not raise PNGGenerationError with png_file set' do
156
- expect { @flag.png }.to_not raise_error(USPSFlags::Errors::PNGGenerationError)
157
+ expect { @flag.png }.to_not raise_error
157
158
  end
158
159
 
159
160
  it 'should return the value of png_file' do