usps_flags 0.5.0 → 0.5.1

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.
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
@@ -4,52 +4,56 @@
4
4
  #
5
5
  # These methods should never need to be called directly.
6
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
7
+ class USPSFlags
8
+ class Helpers
9
+ class ValidFlags
10
+ class << self
11
+ def load_valid_flags
12
+ @squadron_past = %w[PLTC PC]
13
+ @squadron_elected = %w[1LT LTC CDR]
14
+ @squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT]
15
+ @district_past = %w[PDLTC PDC]
16
+ @district_elected = %w[D1LT DLTC DC]
17
+ @district_swallowtail = %w[DLT DAIDE DFLT]
18
+ @national_past = %w[PSTFC PRC PVC PCC]
19
+ @national_elected = %w[STFC RC VC CC]
20
+ @national_swallowtail = %w[NAIDE NFLT]
21
+ end
20
22
 
21
- def load_special_flags
22
- @special = %w[CRUISE OIC ENSIGN] # WHEEL
23
- @us = %w[US]
24
- end
23
+ def load_special_flags
24
+ @special = %w[CRUISE OIC ENSIGN] # WHEEL
25
+ @us = %w[US]
26
+ end
25
27
 
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
28
+ def load_valid_flag_groups
29
+ @past = @squadron_past + @district_past + @national_past
30
+ @squadron = @squadron_past + @squadron_elected + @squadron_swallowtail
31
+ @district = @district_past + @district_elected + @district_swallowtail
32
+ @national = @national_past + @national_elected + @national_swallowtail
33
+ @officer = @squadron + @district + @national
34
+ end
33
35
 
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
36
+ def valid_flags_for(type)
37
+ {
38
+ special: @special, us: @us, bridge: bridge_flags, command: command_flags,
39
+ squadron: @squadron, district: @district, national: @national, past: @past,
40
+ all: @officer + @special + @us, officer: @officer, insignia: @officer - @past,
41
+ swallowtail: @past + @squadron_swallowtail + @district_swallowtail + @national_swallowtail
42
+ }[type]
43
+ end
42
44
 
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
45
+ def bridge_flags
46
+ @squadron_elected.last(2) + @district_elected.last(2) + @national_elected.last(2) +
47
+ @squadron_past.last(2) + @district_past.last(2) + @national_past.last(2)
48
+ end
47
49
 
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
- ]
50
+ def command_flags
51
+ [
52
+ @squadron_elected.last, @district_elected.last, @national_elected.last,
53
+ @squadron_past.last, @district_past.last, @national_past.last
54
+ ]
55
+ end
56
+ end
53
57
  end
54
58
  end
55
59
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: false
2
+
3
+ # Monkey patch to add some formatting methods to Rational.
4
+ #
5
+ # @author Julian Fiander
6
+ # @since 0.1.5
7
+ class USPSFlags
8
+ class Rational
9
+ def initialize(rational)
10
+ @rational = rational
11
+ end
12
+
13
+ # Converts Rational to String
14
+ #
15
+ # If Rational is an improper fraction, removes the integer part to convert to a mixed fraction.
16
+ #
17
+ # @example Mixed fraction
18
+ # Rational(4,3).to_simplified_s #=> "1 1/3"
19
+ # @return [String] If less than 1, fraction. If greater than 1, a mixed fraction.
20
+ def to_simplified_s
21
+ @rational < 1 ? @rational.to_s : [@rational.truncate.to_s, (@rational - @rational.truncate).to_s].join(' ')
22
+ end
23
+
24
+ # Converts Rational to Array
25
+ #
26
+ # If Rational is an improper fraction, removes the integer part to convert to a mixed fraction.
27
+ #
28
+ # @example Mixed fraction
29
+ # Rational(4,3).to_simplified_a #=> [1, Rational(1,3)]
30
+ # @return [Array] If less than 1, fraction. If greater than 1, a mixed fraction.
31
+ def to_simplified_a
32
+ @rational < 1 ? @rational.to_s : [@rational.truncate, (@rational - @rational.truncate)]
33
+ end
34
+ end
35
+ end
@@ -4,51 +4,58 @@ require 'spec_helper'
4
4
 
5
5
  describe USPSFlags::Config do
6
6
  describe 'class variable accessors' do
7
- it 'should return the current flags directory' do
7
+ it 'returns the current flags directory' do
8
8
  expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
9
9
  end
10
10
 
11
- it 'should return the current flags directory' do
11
+ it 'returns the current log directory' do
12
12
  default_log_path = $tmp_flags_dir + '/log'
13
13
  expect(USPSFlags.configuration.log_path).to eql(default_log_path)
14
14
  end
15
15
 
16
- it 'should return a Boolean from clear' do
17
- expect([true, false]).to include(USPSFlags.configuration.clear)
16
+ it 'returns a Boolean from clear' do
17
+ expect(USPSFlags.configuration.clear).to be(true)
18
18
  end
19
19
  end
20
20
 
21
21
  describe 'trident' do
22
- it 'should return a Hash from trident' do
22
+ it 'returns a Hash from trident' do
23
23
  expect(USPSFlags.configuration.trident).to be_a(Hash)
24
24
  end
25
25
  end
26
26
 
27
27
  describe 'configuration constructor' do
28
- it 'should return a properly constructed configuration' do
28
+ it 'returns a properly constructed configuration' do
29
29
  USPSFlags.configure do |config|
30
30
  config.flags_dir = $tmp_flags_dir
31
31
  end
32
32
 
33
33
  expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
34
- expect(USPSFlags.configuration.clear).to eql(true)
34
+ end
35
+
36
+ it 'returns a boolean on configuration clear' do
37
+ USPSFlags.configure do |config|
38
+ config.flags_dir = $tmp_flags_dir
39
+ end
40
+
41
+ expect(USPSFlags.configuration.clear).to be(true)
35
42
  end
36
43
  end
37
44
 
38
45
  describe 'Rails configuration' do
39
- before(:each) do
46
+ before do
40
47
  class Rails
41
48
  def self.root
42
49
  'tmp/rails_app'
43
50
  end
44
51
  end
45
52
 
46
- @config = USPSFlags::Config.new do |config|
53
+ @config = described_class.new do |config|
47
54
  config.flags_dir = $tmp_flags_dir
48
55
  end
49
56
  end
50
57
 
51
- it 'should use the default Rails log directory' do
58
+ it 'uses the default Rails log directory' do
52
59
  expect(@config.log_path).to eql('tmp/rails_app/log')
53
60
  end
54
61
  end
@@ -3,12 +3,19 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe USPSFlags::Core do
6
+ before do
7
+ @fly = USPSFlags::Config::BASE_FLY
8
+ @hoist = USPSFlags::Config::BASE_HOIST
9
+ @red = USPSFlags::Config::RED
10
+ @blue = USPSFlags::Config::BLUE
11
+ end
12
+
6
13
  describe 'trident_spec' do
7
14
  [
8
15
  'Field', 'Specification Heading Information', 'Short Trident', 'Delta Trident', 'Circle Trident', 'Long Trident'
9
16
  ].each do |section|
10
17
  it "should contain the #{section} section" do
11
- expect(USPSFlags::Core.trident_spec).to include("<!-- #{section} -->")
18
+ expect(described_class.trident_spec).to include("<!-- #{section} -->")
12
19
  end
13
20
  end
14
21
  end
@@ -16,27 +23,20 @@ describe USPSFlags::Core do
16
23
  describe 'headers' do
17
24
  ['?xml ', '!DOCTYPE', 'svg ', 'metadata'].each do |tag|
18
25
  it "should contain the #{tag} tag" do
19
- expect(USPSFlags::Core.headers).to include("<#{tag}")
26
+ expect(described_class.headers).to include("<#{tag}")
20
27
  end
21
28
  end
22
29
  end
23
30
 
24
31
  describe 'footer' do
25
- it 'should contain the closing tag' do
26
- expect(USPSFlags::Core.footer).to include('</svg>')
32
+ it 'contains the closing tag' do
33
+ expect(described_class.footer).to include('</svg>')
27
34
  end
28
35
  end
29
36
 
30
- before(:all) do
31
- @fly = USPSFlags::Config::BASE_FLY
32
- @hoist = USPSFlags::Config::BASE_HOIST
33
- @red = USPSFlags::Config::RED
34
- @blue = USPSFlags::Config::BLUE
35
- end
36
-
37
37
  describe 'field' do
38
- it 'should correctly generate the basic field' do
39
- expect(USPSFlags::Core.field).to eql(
38
+ it 'correctlies generate the basic field' do
39
+ expect(described_class.field).to eql(
40
40
  <<~SVG
41
41
  <path d="M 0 0
42
42
  l #{@fly} 0
@@ -48,8 +48,8 @@ describe USPSFlags::Core do
48
48
  )
49
49
  end
50
50
 
51
- it 'should correctly generate the red field' do
52
- expect(USPSFlags::Core.field(color: :red)).to eql(
51
+ it 'correctlies generate the red field' do
52
+ expect(described_class.field(color: :red)).to eql(
53
53
  <<~SVG
54
54
  <path d="M 0 0
55
55
  l #{@fly} 0
@@ -61,8 +61,8 @@ describe USPSFlags::Core do
61
61
  )
62
62
  end
63
63
 
64
- it 'should correctly generate the swallowtail field' do
65
- expect(USPSFlags::Core.field(style: :swallowtail)).to eql(
64
+ it 'correctlies generate the swallowtail field' do
65
+ expect(described_class.field(style: :swallowtail)).to eql(
66
66
  <<~SVG
67
67
  <path d="M 2 1
68
68
  l #{@fly} #{@hoist / 6}
@@ -74,8 +74,8 @@ describe USPSFlags::Core do
74
74
  )
75
75
  end
76
76
 
77
- it 'should correctly generate the blue past field' do
78
- expect(USPSFlags::Core.field(style: :past, color: :blue)).to eql(
77
+ it 'correctlies generate the blue past field' do
78
+ expect(described_class.field(style: :past, color: :blue)).to eql(
79
79
  <<~SVG
80
80
  <g transform="translate(2, 1)">
81
81
  <path d="M 0 5 l #{@fly / 2} #{@hoist * 1 / 12}
@@ -103,36 +103,36 @@ describe USPSFlags::Core do
103
103
  end
104
104
 
105
105
  describe 'trident' do
106
- it 'should correctly generate a short trident' do
107
- expect(USPSFlags::Core.trident(:s)).to include("<path d=\"M #{@fly / 2} #{@hoist / 4}\n")
106
+ it 'correctlies generate a short trident' do
107
+ expect(described_class.trident(:s)).to include("<path d=\"M #{@fly / 2} #{@hoist / 4}\n")
108
108
  end
109
109
 
110
- it 'should correctly generate a delta trident' do
111
- expect(USPSFlags::Core.trident(:d)).to include(
110
+ it 'correctlies generate a delta trident' do
111
+ expect(described_class.trident(:d)).to include(
112
112
  "<g mask=\"url(#delta-mask)\"><path d=\"M #{@fly / 2} #{@hoist * 3 / 16}\n"
113
113
  )
114
114
  end
115
115
 
116
- it 'should correctly generate a circle trident' do
117
- expect(USPSFlags::Core.trident(:stf)).to include(
116
+ it 'correctlies generate a circle trident' do
117
+ expect(described_class.trident(:stf)).to include(
118
118
  "<g mask=\"url(#circle-mask-for-main-spike)\"><path d=\"M #{@fly / 2} #{@hoist / 8}\n"
119
119
  )
120
120
  end
121
121
 
122
- it 'should correctly generate a long trident' do
123
- expect(USPSFlags::Core.trident(:n)).to include("<path d=\"M #{@fly / 2} #{@hoist / 8}\n")
122
+ it 'correctlies generate a long trident' do
123
+ expect(described_class.trident(:n)).to include("<path d=\"M #{@fly / 2} #{@hoist / 8}\n")
124
124
  end
125
125
  end
126
126
 
127
127
  describe 'anchor' do
128
- it 'should correctly generate an anchor' do
129
- expect(USPSFlags::Core.anchor).to include('<mask id="anchor-mask">')
128
+ it 'correctlies generate an anchor' do
129
+ expect(described_class.anchor).to include('<mask id="anchor-mask">')
130
130
  end
131
131
  end
132
132
 
133
133
  describe 'lighthouse' do
134
- it 'should correctly generate a lighthouse' do
135
- expect(USPSFlags::Core.lighthouse).to include('<mask id="lighthouse-mask">')
134
+ it 'correctlies generate a lighthouse' do
135
+ expect(described_class.lighthouse).to include('<mask id="lighthouse-mask">')
136
136
  end
137
137
  end
138
138
  end
@@ -4,14 +4,14 @@ require 'spec_helper'
4
4
 
5
5
  describe USPSFlags::Generate do
6
6
  describe 'general features' do
7
- it 'should generate a flag with the correct size' do
8
- expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include(
7
+ it 'generates a flag with the correct size' do
8
+ expect(described_class.svg('LtC', outfile: '')).to include(
9
9
  'width="1024" height="682" viewBox="0 0 3072 2048"'
10
10
  )
11
11
  end
12
12
 
13
- it 'should generate a flag with the correct field' do
14
- expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include(
13
+ it 'generates a flag with the correct field' do
14
+ expect(described_class.svg('LtC', outfile: '')).to include(
15
15
  <<~SVG
16
16
  <path d="M 0 0
17
17
  l 3072 0
@@ -23,114 +23,117 @@ describe USPSFlags::Generate do
23
23
  )
24
24
  end
25
25
 
26
- it 'should generate a flag with the correct starting position' do
27
- expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include('<path d="M 1536 512')
26
+ it 'generates a flag with the correct starting position' do
27
+ expect(described_class.svg('LtC', outfile: '')).to include('<path d="M 1536 512')
28
28
  end
29
29
 
30
- it 'should generate a flag with the correct trident transformations' do
31
- expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include('<g transform="translate(-512)">')
32
- expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include('<g transform="translate(512)">')
30
+ describe 'lateral transformations' do
31
+ it 'has the correct left transformation' do
32
+ expect(described_class.svg('LtC', outfile: '')).to include('<g transform="translate(-512)">')
33
+ end
34
+
35
+ it 'has the correct right transformation' do
36
+ expect(described_class.svg('LtC', outfile: '')).to include('<g transform="translate(512)">')
37
+ end
33
38
  end
34
39
  end
35
40
 
36
41
  describe 'officer flags' do
37
- [
38
- 'PLTC', 'PC', 'PDLTC', 'PDC', 'PSTFC', 'PRC', 'PVC', 'PCC',
39
- 'PORTCAP', 'FLEETCAP', 'FLT', 'DAIDE', 'DFLT', 'NAIDE', 'NFLT',
40
- 'LT', '1LT', 'LTC', 'CDR', 'DLT', 'D1LT', 'DLTC', 'DC', 'STFC', 'RC', 'VC', 'CC'
42
+ %w[
43
+ PLTC PC PDLTC PDC PSTFC PRC PVC PCC
44
+ PORTCAP FLEETCAP FLT DAIDE DFLT NAIDE NFLT
45
+ LT 1LT LTC CDR DLT D1LT DLTC DC STFC RC VC CC
41
46
  ].each do |flag|
42
47
  it "should generate #{flag}" do
43
- expect(USPSFlags::Generate.svg(flag, outfile: '')).to include("<title>#{flag}</title>")
48
+ expect(described_class.svg(flag, outfile: '')).to include("<title>#{flag}</title>")
44
49
  end
45
50
  end
46
51
  end
47
52
 
48
53
  describe 'pennants' do
49
- it 'should generate the cruise pennant' do
50
- expect(USPSFlags::Generate.svg('Cruise', outfile: '')).to include('<title>Cruise Pennant</title>')
54
+ it 'generates the cruise pennant' do
55
+ expect(described_class.svg('Cruise', outfile: '')).to include('<title>Cruise Pennant</title>')
51
56
  end
52
57
 
53
- it 'should generate the officer-in-charge pennant' do
54
- expect(USPSFlags::Generate.svg('OIC', outfile: '')).to include('<title>Officer-in-Charge Pennant</title>')
58
+ it 'generates the officer-in-charge pennant' do
59
+ expect(described_class.svg('OIC', outfile: '')).to include('<title>Officer-in-Charge Pennant</title>')
55
60
  end
56
61
  end
57
62
 
58
63
  describe 'other flags' do
59
- it 'should generate US' do
60
- expect(USPSFlags::Generate.svg('US', outfile: '')).to include('<title>US Ensign</title>')
64
+ it 'generates US' do
65
+ expect(described_class.svg('US', outfile: '')).to include('<title>US Ensign</title>')
61
66
  end
62
67
 
63
- it 'should generate USPS Ensign' do
64
- expect(USPSFlags::Generate.svg('Ensign', outfile: '')).to include('<title>USPS Ensign</title>')
68
+ it 'generates USPS Ensign' do
69
+ expect(described_class.svg('Ensign', outfile: '')).to include('<title>USPS Ensign</title>')
65
70
  end
66
71
 
67
- it 'should generate the USPS Wheel logo' do
68
- expect(USPSFlags::Generate.svg('Wheel', outfile: '')).to include('<title>USPS Ensign Wheel</title>')
72
+ it 'generates the USPS Wheel logo' do
73
+ expect(described_class.svg('Wheel', outfile: '')).to include('<title>USPS Ensign Wheel</title>')
69
74
  end
70
75
  end
71
76
 
72
77
  describe 'trident specifications' do
73
- it 'should generate the trident specification sheet' do
74
- expect(USPSFlags::Generate.spec(outfile: '')).to include('<title>USPS Trident Specifications</title>')
78
+ it 'generates the trident specification sheet' do
79
+ expect(described_class.spec(outfile: '')).to include('<title>USPS Trident Specifications</title>')
75
80
  end
76
81
 
77
- it 'should generate the trident specification sheet with a scaled border' do
78
- expect(USPSFlags::Generate.spec(outfile: '', scaled_border: true)).to include(
82
+ it 'generates the trident specification sheet with a scaled border' do
83
+ expect(described_class.spec(outfile: '', scaled_border: true)).to include(
79
84
  '<title>USPS Trident Specifications</title>'
80
85
  )
81
86
  end
82
87
 
83
- it 'should generate the trident specification sheet with a fractional field size' do
84
- expect(USPSFlags::Generate.spec(outfile: '', fly: 23.5)).to include('<title>USPS Trident Specifications</title>')
88
+ it 'generates the trident specification sheet with a fractional field size' do
89
+ expect(described_class.spec(outfile: '', fly: 23.5)).to include('<title>USPS Trident Specifications</title>')
85
90
  end
86
91
  end
87
92
 
88
93
  describe 'png' do
89
- before(:each) do
90
- @svg = USPSFlags::Generate.svg('LtC', outfile: '')
94
+ before do
95
+ @svg = described_class.svg('LtC', outfile: '')
91
96
  end
92
97
 
93
- it 'should raise PNGGenerationError without an outfile' do
94
- expect { USPSFlags::Generate.png(@svg, outfile: '') }.to raise_error(USPSFlags::Errors::PNGGenerationError)
98
+ it 'raises PNGGenerationError without an outfile' do
99
+ expect { described_class.png(@svg, outfile: '') }.to raise_error(USPSFlags::Errors::PNGGenerationError)
95
100
  end
96
101
 
97
- it 'should contain the SVG when raising PNGGenerationError without an outfile' do
98
- begin
99
- USPSFlags::Generate.png(@svg, outfile: '')
100
- rescue => e
101
- expect(e.svg).to eql(@svg)
102
- end
102
+ it 'contains the SVG when raising PNGGenerationError without an outfile' do
103
+ described_class.png(@svg, outfile: '')
104
+ rescue StandardError => e
105
+ expect(e.svg).to eql(@svg)
103
106
  end
104
107
 
105
- it 'should not raise PNGGenerationError when correctly configured' do
106
- expect { USPSFlags::Generate.png(@svg, outfile: 'lib/output/PNG/LTC.png') }.to_not raise_error
108
+ it 'does not raise PNGGenerationError when correctly configured' do
109
+ expect { described_class.png(@svg, outfile: 'lib/output/PNG/LTC.png') }.not_to raise_error
107
110
  end
108
111
  end
109
112
 
110
113
  describe 'without an outfile set' do
111
- it 'should print SVG data to the console' do
112
- expect(STDOUT).to receive(:puts).with(USPSFlags::Generate.svg('Lt', outfile: ''), "\n")
113
- USPSFlags::Generate.svg('Lt')
114
+ it 'prints SVG data to the console' do
115
+ expect(STDOUT).to receive(:puts).with(described_class.svg('Lt', outfile: ''), "\n")
116
+ described_class.svg('Lt')
114
117
  end
115
118
  end
116
119
 
117
120
  describe 'static files errors' do
118
- it 'should raise USPSFlags::Errors::StaticFilesGenerationError when not given any true arguments' do
119
- expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: false) }.to raise_error(
121
+ it 'raises USPSFlags::Errors::StaticFilesGenerationError when not given any true arguments' do
122
+ expect { described_class.all(svg: false, png: false, zips: false, reset: false) }.to raise_error(
120
123
  USPSFlags::Errors::StaticFilesGenerationError,
121
124
  'At least one argument switch must be true out of [svg, png, zips, reset].'
122
125
  )
123
126
  end
124
127
 
125
- it 'should raise USPSFlags::Errors::ZipGenerationError when not given any true arguments' do
126
- expect { USPSFlags::Generate.zips(svg: false, png: false) }.to raise_error(
128
+ it 'raises USPSFlags::Errors::ZipGenerationError when not given any true arguments' do
129
+ expect { described_class.zips(svg: false, png: false) }.to raise_error(
127
130
  USPSFlags::Errors::ZipGenerationError, 'At least one argument switch must be true out of [svg, png].'
128
131
  )
129
132
  end
130
133
  end
131
134
 
132
135
  describe 'static files generation', slow: true do
133
- before(:all) do
136
+ before do
134
137
  svg_dir = "#{USPSFlags.configuration.flags_dir}/SVG"
135
138
  png_dir = "#{USPSFlags.configuration.flags_dir}/PNG"
136
139
 
@@ -144,15 +147,15 @@ describe USPSFlags::Generate do
144
147
  ::FileUtils.rm_rf(USPSFlags.configuration.flags_dir)
145
148
  USPSFlags.prepare_flags_dir
146
149
 
147
- USPSFlags::Generate.svg(@svg_flag, outfile: "#{svg_dir}/#{@svg_flag}.svg")
148
- USPSFlags::Generate.svg(@svg_ins_flag, field: false, outfile: "#{svg_dir}/insignia/#{@svg_ins_flag}.svg")
149
- USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_flag, outfile: ''), outfile: "#{png_dir}/#{@png_flag}.png")
150
- USPSFlags::Generate.png(
151
- USPSFlags::Generate.svg(@png_ins_flag, field: false, outfile: ''),
150
+ described_class.svg(@svg_flag, outfile: "#{svg_dir}/#{@svg_flag}.svg")
151
+ described_class.svg(@svg_ins_flag, field: false, outfile: "#{svg_dir}/insignia/#{@svg_ins_flag}.svg")
152
+ described_class.png(described_class.svg(@png_flag, outfile: ''), outfile: "#{png_dir}/#{@png_flag}.png")
153
+ described_class.png(
154
+ described_class.svg(@png_ins_flag, field: false, outfile: ''),
152
155
  trim: true, outfile: "#{png_dir}/insignia/#{@png_ins_flag}.png"
153
156
  )
154
- USPSFlags::Generate.png(
155
- USPSFlags::Generate.svg(@thb_flag, field: false, outfile: ''),
157
+ described_class.png(
158
+ described_class.svg(@thb_flag, field: false, outfile: ''),
156
159
  trim: true, outfile: "#{png_dir}/insignia/#{@thb_flag}.png"
157
160
  )
158
161
  USPSFlags::Helpers.resize_png(
@@ -160,16 +163,16 @@ describe USPSFlags::Generate do
160
163
  )
161
164
  end
162
165
 
163
- it 'should not raise an error while generating all static files' do
164
- expect { USPSFlags::Generate.all(reset: false) }.to_not raise_error
166
+ it 'does not raise an error while generating all static files' do
167
+ expect { described_class.all(reset: false) }.not_to raise_error
165
168
  end
166
169
 
167
170
  describe 'generation logs' do
168
- before(:each) do
171
+ before do
169
172
  @log_contents = ::File.read("#{USPSFlags.configuration.log_path}/flag.log")
170
173
  end
171
174
 
172
- it 'should have generated the correct log output' do
175
+ it 'has generated the correct log output' do
173
176
  correct_log_pattern = <<~LOG
174
177
  Flag | SVG | PNG | Run time
175
178
  ---------------------------------------
@@ -209,19 +212,19 @@ describe USPSFlags::Generate do
209
212
  Generated PNG Zip
210
213
  LOG
211
214
 
212
- correct_log_pattern = correct_log_pattern.
213
- gsub('+', '\+').gsub('|', '\|').
214
- gsub(/#{@svg_flag} | S/, "#{@svg_flag} | \\.").
215
- gsub(/#{@svg_ins_flag} | SI/, "#{@svg_ins_flag} | S\\.").
216
- gsub(/#{@png_flag} | S(.) | F/, "#{@png_flag} | S\1 | \\.").
217
- gsub(/#{@png_ins_flag} | SI | FI/, "#{@png_ins_flag} | SI | F\\.").
218
- gsub(/#{@thm_flag} | SI | FIH(.)K(.)D(.)Ti/, "#{@thm_flag} | SI | FIH\1K\2D\3T\\.")
215
+ correct_log_pattern = correct_log_pattern
216
+ .gsub('+', '\+').gsub('|', '\|')
217
+ .gsub(/#{@svg_flag} | S/, "#{@svg_flag} | \\.")
218
+ .gsub(/#{@svg_ins_flag} | SI/, "#{@svg_ins_flag} | S\\.")
219
+ .gsub(/#{@png_flag} | S(.) | F/, "#{@png_flag} | S\1 | \\.")
220
+ .gsub(/#{@png_ins_flag} | SI | FI/, "#{@png_ins_flag} | SI | F\\.")
221
+ .gsub(/#{@thm_flag} | SI | FIH(.)K(.)D(.)Ti/, "#{@thm_flag} | SI | FIH\1K\2D\3T\\.")
219
222
  correct_log_regexp = Regexp.new(correct_log_pattern)
220
223
 
221
224
  expect(@log_contents).to match(correct_log_regexp)
222
225
  end
223
226
 
224
- it 'should not match an incorrect log output' do
227
+ it 'does not match an incorrect log output' do
225
228
  incorrect_log_pattern = 'PLTC \| -- \| ---------- \| .*{3,6} s'
226
229
 
227
230
  incorrect_log_regexp = Regexp.new(incorrect_log_pattern)
@@ -230,12 +233,12 @@ describe USPSFlags::Generate do
230
233
  end
231
234
  end
232
235
 
233
- it 'should not raise an error while clearing all static files' do
234
- expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: true) }.to_not raise_error
236
+ it 'does not raise an error while clearing all static files' do
237
+ expect { described_class.all(svg: false, png: false, zips: false, reset: true) }.not_to raise_error
235
238
  end
236
239
 
237
- it 'should not raise an error while generating zip files' do
238
- expect { USPSFlags::Generate.zips }.to_not raise_error
240
+ it 'does not raise an error while generating zip files' do
241
+ expect { described_class.zips }.not_to raise_error
239
242
  end
240
243
  end
241
244
  end