usps_flags 0.1.17
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 +7 -0
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/.yardoc/checksums +6 -0
- data/.yardoc/complete +0 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/.yardopts +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +674 -0
- data/README.md +136 -0
- data/Rakefile +7 -0
- data/certs/jfiander.pem +21 -0
- data/lib/rational.rb +37 -0
- data/lib/usps_flags.rb +140 -0
- data/lib/usps_flags/config.rb +115 -0
- data/lib/usps_flags/core.rb +909 -0
- data/lib/usps_flags/generate.rb +545 -0
- data/lib/usps_flags/helpers.rb +248 -0
- data/spec/rational_spec.rb +13 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/usps_flags/config_spec.rb +27 -0
- data/spec/usps_flags/core_spec.rb +133 -0
- data/spec/usps_flags/generate_spec.rb +20 -0
- data/spec/usps_flags/helpers_spec.rb +13 -0
- data/spec/usps_flags_spec.rb +157 -0
- data/usps_flags.gemspec +27 -0
- metadata +223 -0
- metadata.gz.sig +2 -0
@@ -0,0 +1,248 @@
|
|
1
|
+
# Container class for helper methods.
|
2
|
+
class USPSFlags::Helpers
|
3
|
+
# Valid options for flag generation.
|
4
|
+
#
|
5
|
+
# @param [Symbol] type Specify subset of flags.
|
6
|
+
# @option type [Symbol] :all All flags
|
7
|
+
# @option type [Symbol] :officer Officer flags
|
8
|
+
# @option type [Symbol] :insignia Insignia-eligible officer flags (no past officers)
|
9
|
+
# @option type [Symbol] :squadron Squadron-level officer flags
|
10
|
+
# @option type [Symbol] :district District-level officer flags
|
11
|
+
# @option type [Symbol] :national National-level officer flags
|
12
|
+
# @option type [Symbol] :special Special flags
|
13
|
+
# @option type [Symbol] :us US flag
|
14
|
+
# @return [Array] Valid options for flag generation (based on the provided type).
|
15
|
+
def self.valid_flags(type = :all)
|
16
|
+
squadron = %w[
|
17
|
+
PLTC
|
18
|
+
PC
|
19
|
+
PORTCAP
|
20
|
+
FLEETCAP
|
21
|
+
LT
|
22
|
+
FLT
|
23
|
+
1LT
|
24
|
+
LTC
|
25
|
+
CDR
|
26
|
+
]
|
27
|
+
|
28
|
+
district = %w[
|
29
|
+
PDLTC
|
30
|
+
PDC
|
31
|
+
DLT
|
32
|
+
DAIDE
|
33
|
+
DFLT
|
34
|
+
D1LT
|
35
|
+
DLTC
|
36
|
+
DC
|
37
|
+
]
|
38
|
+
|
39
|
+
national = %w[
|
40
|
+
PSTFC
|
41
|
+
PRC
|
42
|
+
PVC
|
43
|
+
PCC
|
44
|
+
NAIDE
|
45
|
+
NFLT
|
46
|
+
STFC
|
47
|
+
RC
|
48
|
+
VC
|
49
|
+
CC
|
50
|
+
]
|
51
|
+
|
52
|
+
past = %w[
|
53
|
+
PLTC
|
54
|
+
PC
|
55
|
+
PDLTC
|
56
|
+
PDC
|
57
|
+
PSTFC
|
58
|
+
PRC
|
59
|
+
PVC
|
60
|
+
PCC
|
61
|
+
]
|
62
|
+
|
63
|
+
special = %w[
|
64
|
+
CRUISE
|
65
|
+
OIC
|
66
|
+
ENSIGN
|
67
|
+
WHEEL
|
68
|
+
]
|
69
|
+
|
70
|
+
us = %w[
|
71
|
+
US
|
72
|
+
]
|
73
|
+
|
74
|
+
case type
|
75
|
+
when :all
|
76
|
+
squadron + district + national + special + us
|
77
|
+
when :officer
|
78
|
+
squadron + district + national
|
79
|
+
when :insignia
|
80
|
+
squadron + district + national - past
|
81
|
+
when :squadron
|
82
|
+
squadron
|
83
|
+
when :district
|
84
|
+
district
|
85
|
+
when :national
|
86
|
+
national
|
87
|
+
when :special
|
88
|
+
special
|
89
|
+
when :us
|
90
|
+
us
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Displays an overlay grid with regularly spaced locator markers.
|
95
|
+
#
|
96
|
+
# This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
|
97
|
+
# @private
|
98
|
+
def self.grid(width: USPSFlags::Config::BASE_FLY, height: USPSFlags::Config::BASE_HOIST)
|
99
|
+
<<~SVG
|
100
|
+
<circle cx="0" cy="0" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
101
|
+
<circle cx="#{width}" cy="0" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
102
|
+
<circle cx="#{width}" cy="#{height}" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
103
|
+
<circle cx="0" cy="#{height}" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
104
|
+
|
105
|
+
<circle cx="#{width*1/4}" cy="#{height/2}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
106
|
+
<circle cx="#{width*3/4}" cy="#{height/2}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
107
|
+
|
108
|
+
<circle cx="#{width/2}" cy="#{height*1/4}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
109
|
+
<circle cx="#{width/2}" cy="#{height/2}" r="#{width/60}" fill="#000000" fill-opacity="0.4" />
|
110
|
+
<circle cx="#{width/2}" cy="#{height/2}" r="#{width/75}" fill="#CCCCCC" fill-opacity="0.4" />
|
111
|
+
<circle cx="#{width/2}" cy="#{height/2}" r="#{width/100}" fill="#000000" fill-opacity="0.4" />
|
112
|
+
<circle cx="#{width/2}" cy="#{height*3/4}" r="#{width/60}" fill="#999999" fill-opacity="0.4" />
|
113
|
+
|
114
|
+
<line x1="0" y1="0" x2="#{width}" y2="0" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
115
|
+
<line x1="0" y1="#{height*1/4}" x2="#{width}" y2="#{height*1/4}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
116
|
+
<line x1="0" y1="#{height/2}" x2="#{width}" y2="#{height/2}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
117
|
+
<line x1="0" y1="#{height*3/4}" x2="#{width}" y2="#{height*3/4}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
118
|
+
<line x1="0" y1="#{height}" x2="#{width}" y2="#{height}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
119
|
+
|
120
|
+
<line y1="0" x1="0" y2="#{height}" x2="0" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
121
|
+
<line y1="0" x1="#{width*1/6}" y2="#{height}" x2="#{width*1/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
122
|
+
<line y1="0" x1="#{width*2/6}" y2="#{height}" x2="#{width*2/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
123
|
+
<line y1="0" x1="#{width*3/6}" y2="#{height}" x2="#{width*3/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
124
|
+
<line y1="0" x1="#{width*4/6}" y2="#{height}" x2="#{width*4/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
125
|
+
<line y1="0" x1="#{width*5/6}" y2="#{height}" x2="#{width*5/6}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
126
|
+
<line y1="0" x1="#{width}" y2="#{height}" x2="#{width}" stroke="#333333" stroke-width="#{width/600}" stroke-opacity="0.5" />
|
127
|
+
|
128
|
+
<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" />
|
129
|
+
<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" />
|
130
|
+
<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" />
|
131
|
+
<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" />
|
132
|
+
|
133
|
+
SVG
|
134
|
+
end
|
135
|
+
|
136
|
+
# Displays an overlay indicator of concentric circles and radiating lines.
|
137
|
+
#
|
138
|
+
# This is useful for adjusting or creating new SVG data generators, but should not otherwise need to be called.
|
139
|
+
# @private
|
140
|
+
def self.locator
|
141
|
+
<<~SVG
|
142
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY*2}" fill="#000000" fill-opacity="0.4" />
|
143
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY}" fill="#333333" fill-opacity="0.4" />
|
144
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/2}" fill="#666666" fill-opacity="0.4" />
|
145
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/4}" fill="#999999" fill-opacity="0.4" />
|
146
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/8}" fill="#CCCCCC" fill-opacity="0.4" />
|
147
|
+
<circle cx="0" cy="0" r="#{USPSFlags::Config::BASE_FLY/16}" fill="#FFFFFF" fill-opacity="0.4" />
|
148
|
+
|
149
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="-#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
150
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="#{USPSFlags::Config::BASE_HOIST}" x2="#{USPSFlags::Config::BASE_FLY}" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
151
|
+
<line x1="0" y1="#{USPSFlags::Config::BASE_HOIST}" x2="0" y2="-#{USPSFlags::Config::BASE_HOIST}" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
152
|
+
<line x1="-#{USPSFlags::Config::BASE_FLY}" y1="0" x2="#{USPSFlags::Config::BASE_FLY}" y2="0" stroke="#FFFFFF" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
153
|
+
|
154
|
+
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY/30}" height="#{USPSFlags::Config::BASE_FLY/30}" fill="#333333" fill-opacity="0.6" />
|
155
|
+
SVG
|
156
|
+
end
|
157
|
+
|
158
|
+
# Creates a vertical arrow for the trident spec sheet.
|
159
|
+
#
|
160
|
+
# This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
|
161
|
+
# @private
|
162
|
+
def self.v_arrow(x, top, bottom, pointer_top = nil, pointer_bottom = nil, label: nil, label_offset: (USPSFlags::Config::BASE_FLY/120), label_offset_y: 0, label_align: "left", color: "#CCCCCC", stroke_width: (USPSFlags::Config::BASE_FLY/600), stroke_dash: "10, 10", font_size: (USPSFlags::Config::BASE_FLY/60), arrow_size: (USPSFlags::Config::BASE_FLY/120), fly: USPSFlags::Config::BASE_FLY, unit: nil)
|
163
|
+
label = bottom - top if label.nil?
|
164
|
+
label = label.to_i if label - label.to_i == 0
|
165
|
+
label = Rational(label) * fly / USPSFlags::Config::BASE_FLY
|
166
|
+
if label == label.to_i
|
167
|
+
label = label.to_i
|
168
|
+
label_fraction = ""
|
169
|
+
else
|
170
|
+
label, label_fraction = label.to_simplified_a
|
171
|
+
end
|
172
|
+
svg = ""
|
173
|
+
unless pointer_top.nil?
|
174
|
+
svg << <<~SVG
|
175
|
+
<line x1="#{x}" y1="#{top}" x2="#{pointer_top}" y2="#{top}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
|
176
|
+
SVG
|
177
|
+
end
|
178
|
+
unless pointer_bottom.nil?
|
179
|
+
svg << <<~SVG
|
180
|
+
<line x1="#{x}" y1="#{bottom}" x2="#{pointer_bottom}" y2="#{bottom}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
|
181
|
+
SVG
|
182
|
+
end
|
183
|
+
|
184
|
+
svg << <<~SVG
|
185
|
+
<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" />
|
186
|
+
<g>
|
187
|
+
<style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
|
188
|
+
<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>
|
189
|
+
</g>
|
190
|
+
SVG
|
191
|
+
|
192
|
+
svg
|
193
|
+
end
|
194
|
+
|
195
|
+
# Creates a horizontal arrow for the trident spec sheet.
|
196
|
+
#
|
197
|
+
# This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
|
198
|
+
# @private
|
199
|
+
def self.h_arrow(y, left, right, pointer_left = nil, pointer_right = nil, label: nil, label_offset: (USPSFlags::Config::BASE_FLY/45), label_offset_x: 0, label_align: "middle", color: "#CCCCCC", stroke_width: (USPSFlags::Config::BASE_FLY/600), stroke_dash: "10, 10", font_size: (USPSFlags::Config::BASE_FLY/60), arrow_size: (USPSFlags::Config::BASE_FLY/120), fly: USPSFlags::Config::BASE_FLY, unit: nil)
|
200
|
+
label = right - left if label.nil?
|
201
|
+
label = label.to_i if label - label.to_i == 0
|
202
|
+
label = Rational(label) * fly / USPSFlags::Config::BASE_FLY
|
203
|
+
if label == label.to_i
|
204
|
+
label = label.to_i
|
205
|
+
label_fraction = ""
|
206
|
+
else
|
207
|
+
label, label_fraction = label.to_simplified_a
|
208
|
+
end
|
209
|
+
svg = ""
|
210
|
+
unless pointer_left.nil?
|
211
|
+
svg << <<~SVG
|
212
|
+
<line x1="#{left}" y1="#{y}" x2="#{left}" y2="#{pointer_left}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
|
213
|
+
SVG
|
214
|
+
end
|
215
|
+
unless pointer_right.nil?
|
216
|
+
svg << <<~SVG
|
217
|
+
<line x1="#{right}" y1="#{y}" x2="#{right}" y2="#{pointer_right}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
|
218
|
+
SVG
|
219
|
+
end
|
220
|
+
|
221
|
+
svg << <<~SVG
|
222
|
+
<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" />
|
223
|
+
<g>
|
224
|
+
<style><![CDATA[tspan{font-size: #{USPSFlags::Config::FRACTION_SCALE}%;}]]></style>
|
225
|
+
<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>
|
226
|
+
</g>
|
227
|
+
SVG
|
228
|
+
|
229
|
+
svg
|
230
|
+
end
|
231
|
+
|
232
|
+
# Prints message(s) to the console and logs them.
|
233
|
+
#
|
234
|
+
# This should never need to be called directly.
|
235
|
+
# @private
|
236
|
+
def self.log(*messages)
|
237
|
+
::FileUtils.mkdir_p(USPSFlags::Config.log_path)
|
238
|
+
log_file = File.open("#{USPSFlags::Config.log_path}/flag.log", 'a')
|
239
|
+
messages.each do |message|
|
240
|
+
[STDOUT, log_file].each do |f|
|
241
|
+
f.write(message)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
log_file.close
|
245
|
+
|
246
|
+
messages
|
247
|
+
end
|
248
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rational do
|
4
|
+
describe "monkey patches" do
|
5
|
+
it "should render a simplified fraction as an Array" do
|
6
|
+
expect(Rational(4,3).to_simplified_a).to eql([1, Rational(1,3)])
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should render a simplified fraction as a String" do
|
10
|
+
expect(Rational(4,3).to_simplified_s).to eql("1 1/3")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
require 'bundler/setup'
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
require 'usps_flags' # Contains direct SVG matching
|
7
|
+
# require 'fileutils'
|
8
|
+
# require 'zip'
|
9
|
+
# require 'mini_magick'
|
10
|
+
require 'usps_flags/config'
|
11
|
+
require 'usps_flags/helpers'
|
12
|
+
require 'usps_flags/core' # Contains direct SVG matching
|
13
|
+
require 'usps_flags/generate'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
# some (optional) config here
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe USPSFlags::Config do
|
4
|
+
describe "flags_dir" do
|
5
|
+
it "should return the current flags directory" do
|
6
|
+
default_flags_dir = File.dirname(__dir__).gsub("/spec", "/lib") + "/output"
|
7
|
+
expect(USPSFlags::Config.flags_dir).to eql(default_flags_dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return the new flags directory when given a new path" do
|
11
|
+
new_flags_dir = "#{File.dirname(__dir__)}/flags"
|
12
|
+
expect(USPSFlags::Config.flags_dir(new_flags_dir)).to eql(new_flags_dir)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "trident" do
|
17
|
+
it "should return a Hash from trident" do
|
18
|
+
expect(USPSFlags::Config.trident).to be_a(Hash)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "use_larger_tridents" do
|
23
|
+
it "should return a Boolean from use_larger_tridents" do
|
24
|
+
expect([true, false]).to include(USPSFlags::Config.use_larger_tridents)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe USPSFlags::Core do
|
4
|
+
describe "trident_spec" do
|
5
|
+
["Field", "Specification Heading Information", "Short Trident", "Delta Trident", "Circle Trident", "Long Trident"].each do |section|
|
6
|
+
it "should contain the #{section} section" do
|
7
|
+
expect(USPSFlags::Core.trident_spec).to include("<!-- #{section} -->")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "headers" do
|
13
|
+
["?xml ", "!DOCTYPE", "svg ", "metadata"].each do |tag|
|
14
|
+
it "should contain the #{tag} tag" do
|
15
|
+
expect(USPSFlags::Core.headers).to include("<#{tag}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "footer" do
|
21
|
+
it "should contain the closing tag" do
|
22
|
+
expect(USPSFlags::Core.footer).to include("</svg>")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
before(:all) do
|
27
|
+
@fly = USPSFlags::Config::BASE_FLY
|
28
|
+
@hoist = USPSFlags::Config::BASE_HOIST
|
29
|
+
@red = USPSFlags::Config::RED
|
30
|
+
@blue = USPSFlags::Config::BLUE
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "field" do
|
34
|
+
it "should correctly generate the basic field" do
|
35
|
+
expect(USPSFlags::Core.field).to eql(
|
36
|
+
<<~SVG
|
37
|
+
<path d="M 0 0
|
38
|
+
l #{@fly} 0
|
39
|
+
l 0 #{@hoist}
|
40
|
+
l -#{@fly} 0
|
41
|
+
l 0 -#{@hoist}
|
42
|
+
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
43
|
+
SVG
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should correctly generate the red field" do
|
48
|
+
|
49
|
+
expect(USPSFlags::Core.field(color: :red)).to eql(
|
50
|
+
<<~SVG
|
51
|
+
<path d="M 0 0
|
52
|
+
l #{@fly} 0
|
53
|
+
l 0 #{@hoist}
|
54
|
+
l -#{@fly} 0
|
55
|
+
l 0 -#{@hoist}
|
56
|
+
" fill="#{@red}" />
|
57
|
+
SVG
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should correctly generate the swallowtail field" do
|
62
|
+
expect(USPSFlags::Core.field(style: :swallowtail)).to eql(
|
63
|
+
<<~SVG
|
64
|
+
<path d="M 0 0
|
65
|
+
l #{@fly} #{@hoist/6}
|
66
|
+
l -#{@fly/5} #{@hoist/3}
|
67
|
+
l #{@fly/5} #{@hoist/3}
|
68
|
+
l -#{@fly} #{@hoist/6}
|
69
|
+
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
70
|
+
SVG
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should correctly generate the blue past field" do
|
75
|
+
expect(USPSFlags::Core.field(style: :past, color: :blue)).to eql(
|
76
|
+
<<~SVG
|
77
|
+
<path d="M 0 0
|
78
|
+
l #{@fly/2} #{@hoist*1/12}
|
79
|
+
l 0 #{@hoist*10/12}
|
80
|
+
l -#{@fly/2} #{@hoist*1/12}
|
81
|
+
" fill="#{@blue}" />
|
82
|
+
<path d="M #{@fly/2} #{@hoist*1/12}
|
83
|
+
l #{@fly/4} #{@hoist*1/24}
|
84
|
+
l 0 #{@hoist*9/12}
|
85
|
+
l -#{@fly/4} #{@hoist*1/24}
|
86
|
+
" fill="#FFFFFF" />
|
87
|
+
<path d="M #{@fly*3/4} #{@hoist*3/24}
|
88
|
+
l #{@fly/4} #{@hoist*1/24}
|
89
|
+
l -#{@fly/5} #{@hoist/3}
|
90
|
+
l #{@fly/5} #{@hoist/3}
|
91
|
+
l -#{@fly/4} #{@hoist*1/24}
|
92
|
+
" fill="#{@red}" />
|
93
|
+
<path d="M 0 0
|
94
|
+
l #{@fly} #{@hoist/6}
|
95
|
+
l -#{@fly/5} #{@hoist/3}
|
96
|
+
l #{@fly/5} #{@hoist/3}
|
97
|
+
l -#{@fly} #{@hoist/6}
|
98
|
+
" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
99
|
+
SVG
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "trident" do
|
105
|
+
it "should correctly generate a short trident" do
|
106
|
+
expect(USPSFlags::Core.trident(:s)).to include("<path d=\"M #{@fly/2} #{@hoist/4}\n")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should correctly generate a delta trident" do
|
110
|
+
expect(USPSFlags::Core.trident(:d)).to include("<g mask=\"url(#delta-mask)\"><path d=\"M #{@fly/2} #{@hoist*3/16}\n")
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should correctly generate a circle trident" do
|
114
|
+
expect(USPSFlags::Core.trident(:stf)).to include("<g mask=\"url(#circle-mask-for-main-spike)\"><path d=\"M #{@fly/2} #{@hoist/8}\n")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should correctly generate a long trident" do
|
118
|
+
expect(USPSFlags::Core.trident(:n)).to include("<path d=\"M #{@fly/2} #{@hoist/8}\n")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "anchor" do
|
123
|
+
it "should correctly generate an anchor" do
|
124
|
+
expect(USPSFlags::Core.anchor).to include("<mask id=\"anchor-mask\">")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "lighthouse" do
|
129
|
+
it "should correctly generate a lighthouse" do
|
130
|
+
expect(USPSFlags::Core.lighthouse).to include("<mask id=\"lighthouse-mask\">")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe USPSFlags::Generate do
|
4
|
+
it "should get the correct flag" do
|
5
|
+
expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("width=\"1024pt\" height=\"682pt\" viewBox=\"0 0 3072 2048\"")
|
6
|
+
expect(USPSFlags::Generate.get("LtC", outfile: "")).to include(
|
7
|
+
<<~SVG
|
8
|
+
<path d="M 0 0
|
9
|
+
l 3072 0
|
10
|
+
l 0 2048
|
11
|
+
l -3072 0
|
12
|
+
l 0 -2048
|
13
|
+
" fill="#BF0D3E" />
|
14
|
+
SVG
|
15
|
+
)
|
16
|
+
expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("<path d=\"M 1536 512")
|
17
|
+
expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("<g transform=\"translate(-512)\">")
|
18
|
+
expect(USPSFlags::Generate.get("LtC", outfile: "")).to include("<g transform=\"translate(512)\">")
|
19
|
+
end
|
20
|
+
end
|