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.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -11
- data/.travis.yml +1 -1
- data/Gemfile.lock +5 -2
- data/README.md +6 -0
- data/lib/usps_flags.rb +35 -44
- data/lib/usps_flags/config.rb +89 -87
- data/lib/usps_flags/core.rb +44 -42
- data/lib/usps_flags/core/ensign.rb +53 -49
- data/lib/usps_flags/core/field.rb +96 -92
- data/lib/usps_flags/core/footer.rb +9 -5
- data/lib/usps_flags/core/headers.rb +58 -48
- data/lib/usps_flags/core/icons.rb +11 -7
- data/lib/usps_flags/core/icons/anchor.rb +62 -56
- data/lib/usps_flags/core/icons/binoculars.rb +21 -15
- data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
- data/lib/usps_flags/core/icons/star.rb +21 -15
- data/lib/usps_flags/core/icons/trident.rb +136 -127
- data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
- data/lib/usps_flags/core/icons/trumpet.rb +34 -28
- data/lib/usps_flags/core/pennant.rb +50 -46
- data/lib/usps_flags/core/trident_spec.rb +135 -131
- data/lib/usps_flags/core/trident_specs.rb +11 -7
- data/lib/usps_flags/core/trident_specs/base.rb +36 -26
- data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
- data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
- data/lib/usps_flags/core/trident_specs/header.rb +56 -50
- data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
- data/lib/usps_flags/core/trident_specs/long.rb +41 -25
- data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
- data/lib/usps_flags/core/trident_specs/short.rb +30 -156
- data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
- data/lib/usps_flags/core/tridents.rb +54 -50
- data/lib/usps_flags/core/us.rb +40 -44
- data/lib/usps_flags/core/wheel.rb +7 -3
- data/lib/usps_flags/errors.rb +25 -23
- data/lib/usps_flags/generate.rb +111 -107
- data/lib/usps_flags/generate/flag.rb +160 -157
- data/lib/usps_flags/generate/generator_methods.rb +139 -0
- data/lib/usps_flags/generate/helper_methods.rb +88 -0
- data/lib/usps_flags/helpers.rb +163 -165
- data/lib/usps_flags/helpers/builders.rb +92 -85
- data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
- data/lib/usps_flags/helpers/valid_flags.rb +45 -41
- data/lib/usps_flags/rational.rb +35 -0
- data/spec/usps_flags/config_spec.rb +17 -10
- data/spec/usps_flags/core_spec.rb +31 -31
- data/spec/usps_flags/generate_spec.rb +76 -73
- data/spec/usps_flags/helpers_spec.rb +8 -8
- data/spec/usps_flags/rational_spec.rb +17 -0
- data/spec/usps_flags_spec.rb +19 -21
- data/usps_flags.gemspec +7 -6
- metadata +34 -10
- data/lib/rational.rb +0 -39
- data/lib/usps_flags/generate/private.rb +0 -199
- 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
|
-
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def load_special_flags
|
24
|
+
@special = %w[CRUISE OIC ENSIGN] # WHEEL
|
25
|
+
@us = %w[US]
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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 '
|
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 '
|
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 '
|
17
|
-
expect(
|
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 '
|
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 '
|
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
|
-
|
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
|
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 =
|
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 '
|
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(
|
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(
|
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 '
|
26
|
-
expect(
|
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 '
|
39
|
-
expect(
|
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 '
|
52
|
-
expect(
|
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 '
|
65
|
-
expect(
|
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 '
|
78
|
-
expect(
|
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 '
|
107
|
-
expect(
|
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 '
|
111
|
-
expect(
|
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 '
|
117
|
-
expect(
|
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 '
|
123
|
-
expect(
|
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 '
|
129
|
-
expect(
|
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 '
|
135
|
-
expect(
|
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 '
|
8
|
-
expect(
|
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 '
|
14
|
-
expect(
|
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 '
|
27
|
-
expect(
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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(
|
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 '
|
50
|
-
expect(
|
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 '
|
54
|
-
expect(
|
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 '
|
60
|
-
expect(
|
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 '
|
64
|
-
expect(
|
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 '
|
68
|
-
expect(
|
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 '
|
74
|
-
expect(
|
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 '
|
78
|
-
expect(
|
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 '
|
84
|
-
expect(
|
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
|
90
|
-
@svg =
|
94
|
+
before do
|
95
|
+
@svg = described_class.svg('LtC', outfile: '')
|
91
96
|
end
|
92
97
|
|
93
|
-
it '
|
94
|
-
expect {
|
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 '
|
98
|
-
|
99
|
-
|
100
|
-
|
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 '
|
106
|
-
expect {
|
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 '
|
112
|
-
expect(STDOUT).to receive(:puts).with(
|
113
|
-
|
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 '
|
119
|
-
expect {
|
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 '
|
126
|
-
expect {
|
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
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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
|
-
|
155
|
-
|
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 '
|
164
|
-
expect {
|
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
|
171
|
+
before do
|
169
172
|
@log_contents = ::File.read("#{USPSFlags.configuration.log_path}/flag.log")
|
170
173
|
end
|
171
174
|
|
172
|
-
it '
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
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 '
|
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 '
|
234
|
-
expect {
|
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 '
|
238
|
-
expect {
|
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
|