usps_flags 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,60 +4,70 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@view_width = width * scale
|
18
|
-
@view_height = height * scale
|
19
|
-
end
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
class Headers
|
10
|
+
def initialize(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
|
11
|
+
@width = width
|
12
|
+
@height = height
|
13
|
+
@title = title
|
14
|
+
scale ||= 3
|
15
|
+
@generated_at = Time.now.strftime('%Y%m%d.%H%S%z')
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
if @width.nil? || @height.nil?
|
18
|
+
no_sizes(scale, pennant)
|
19
|
+
else
|
20
|
+
set_view_size(width, height, scale)
|
21
|
+
end
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
def svg
|
25
|
+
svg = +''
|
26
|
+
svg << header_top
|
27
|
+
svg << trademark unless @title == 'US Ensign'
|
28
|
+
svg << '</metadata>'
|
29
29
|
|
30
|
-
|
30
|
+
svg
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
@width = USPSFlags::Config::BASE_FLY / scale
|
34
|
-
@height = (@width * Rational(2, 3)).to_i
|
35
|
-
@view_width = USPSFlags::Config::BASE_FLY
|
36
|
-
@view_height = USPSFlags::Config::BASE_HOIST
|
37
|
-
set_pennant_height(@height) if pennant
|
38
|
-
end
|
33
|
+
private
|
39
34
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
def no_sizes(scale, pennant)
|
36
|
+
@width = USPSFlags::Config::BASE_FLY / scale
|
37
|
+
@height = (@width * Rational(2, 3)).to_i
|
38
|
+
@view_width = USPSFlags::Config::BASE_FLY
|
39
|
+
@view_height = USPSFlags::Config::BASE_HOIST
|
40
|
+
set_pennant_height(@height) if pennant
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
43
|
+
def set_pennant_height(height)
|
44
|
+
@height = height / 4
|
45
|
+
@view_height = USPSFlags::Config::BASE_HOIST / 4
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_view_size(width, height, scale)
|
49
|
+
@view_width = width * scale
|
50
|
+
@view_height = height * scale
|
51
|
+
end
|
52
|
+
|
53
|
+
def header_top
|
54
|
+
<<~SVG
|
55
|
+
<?xml version="1.0" standalone="no"?>
|
56
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
57
|
+
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="#{@width}" height="#{@height}" viewBox="0 0 #{@view_width} #{@view_height}" preserveAspectRatio="xMidYMid meet">
|
58
|
+
<title>#{@title}</title>
|
59
|
+
<metadata>
|
60
|
+
<desc id="created-by">Julian Fiander</desc>
|
61
|
+
<desc id="generated-at">#{@generated_at}</desc>
|
62
|
+
SVG
|
63
|
+
end
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
65
|
+
def trademark
|
66
|
+
<<~SVG
|
67
|
+
<desc id="trademark-desc">This image is a registered trademark of United States Power Squadrons.</desc>
|
68
|
+
<desc id="trademark-link">https://www.usps.org/images/secretary/itcom/trademark.pdf</desc>
|
69
|
+
SVG
|
70
|
+
end
|
71
|
+
end
|
62
72
|
end
|
63
73
|
end
|
@@ -4,11 +4,15 @@
|
|
4
4
|
#
|
5
5
|
# These methods should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
module Icons
|
10
|
+
require 'usps_flags/core/icons/anchor'
|
11
|
+
require 'usps_flags/core/icons/binoculars'
|
12
|
+
require 'usps_flags/core/icons/lighthouse'
|
13
|
+
require 'usps_flags/core/icons/star'
|
14
|
+
require 'usps_flags/core/icons/trident'
|
15
|
+
require 'usps_flags/core/icons/trumpet'
|
16
|
+
end
|
17
|
+
end
|
14
18
|
end
|
@@ -4,63 +4,69 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
module Icons
|
10
|
+
class Anchor
|
11
|
+
def initialize(color: :red)
|
12
|
+
@color_code = case color
|
13
|
+
when :red
|
14
|
+
USPSFlags::Config::RED
|
15
|
+
when :white
|
16
|
+
'#FFFFFF'
|
17
|
+
end
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
def svg
|
21
|
+
<<~SVG
|
22
|
+
<mask id="anchor-mask">
|
23
|
+
<g>
|
24
|
+
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
|
25
|
+
<path fill="#000000" d="M1252.3076435897437 462.05128846153843
|
26
|
+
c-55.62957153846173-45.08196512820513-96.39672312820517 23.744812948717993-88.20503230769259 51.79489025641044 6.653223282051158 27.53726679487147 50.02959307692299 72.62890461538461 98.46155051282062 25.641023846153644-27.978308974358924-21.85968564102552-43.491535897435824-37.83963128205124-8.717984871794897-76.4102912820511
|
27
|
+
M1270.7816162109375 632.2105102539062
|
28
|
+
c11.54851016276666-6.899249317733052 39.425036990907756-18.726567019718118 51.28209197215574-38.46155724158655 18.5237216479145 6.418855931977646 41.891453418341825 56.769453150028085 42.05127579126565 78.97439966446314-44.455562242460246.1536644631529498-70.91589675334876-3.7750424355801897-92.82043457031227-4.102564102564088-.3660762785023053-20.3275216669839.4958814355788945-14.34922979993803-.5129331931091201-35.3846435546875
|
29
|
+
M1271.807373046875 800.9284542768429
|
30
|
+
c17.452943326530885-.46905043663332435 38.66574607901384-1.5444581957890477 72.82039701021631-2.051257011217899 19.28285605940755 11.288072979443086-54.75933644042357 64.92938750941744-76.92296424278834 66.15380859375-2.1636278023652267-19.80121994130843.7052539023432018-33.79374165575666-.00010016025635195547-64.61535801031664
|
31
|
+
M1189.4276123046875 1008.6016845703125
|
32
|
+
c2.974817410010928 29.162871686922244.9565995146047044 90.80892096853563-5.128155048076906 121.53843336838918-40.443728921655975-2.6038209334792555-89.68029403366631-82.60878014049194 3.0768291766826223-122.05126170622987
|
33
|
+
M1322.38818359375 1290.0933837890625
|
34
|
+
c19.593626045193105-1.2347605841421228 95.16059107098704 40.021664246269665 96.4102783203125 68.718017578125-14.134928135289783 16.901481536983738-35.666444420437074 27.636734330172885-47.17954351963135 29.743511493389406-22.282329868425222-9.688094631655076-55.15658121378351-81.19370160837752-50.256350786258054-97.4358097956731" />
|
35
|
+
</g>
|
36
|
+
</mask>
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
38
|
+
<path mask="url(#anchor-mask)" fill="#{@color_code}" d="M1182.0512562460422,634.8718105128619
|
39
|
+
c-127.50414031806645,-57.87980084448043,-98.33494194360924,-157.05652261543366,-81.0255763281848,-194.8718025641362
|
40
|
+
c38.84781387183102,-83.96914338466655,157.00304879489136,-82.85448702564872,195.89744384618598,-47.17948923074607
|
41
|
+
c24.53542477435849,21.316034000046102,60.18456838981683,51.05085879482306,57.435807435916786,113.84615205126914
|
42
|
+
c73.14866787698952,76.12863520509234,71.40198169752557,88.51520500000265,97.43599743583059,173.33334102563083
|
43
|
+
c98.8545389450071,4.818131232624637,99.55414898847789,104.61193489364757,-8.205124358939429,109.74356999999225
|
44
|
+
c-25.708004789625875,64.61882453844396,-67.14435745637093,120.94832935895647,-172.3077023077326,169.2307871794976
|
45
|
+
c-2.5992382255190023,70.84656448715225,13.776934159119264,186.8525220513062,24.61535871798901,234.8717266666564
|
46
|
+
c65.19738749240719,10.070483589747028,154.51026231285846,61.984337666644706,189.74357649238618,111.79495410250729
|
47
|
+
c8.566643512772089,-9.676561051226827,56.736362820500744,-40.8957688974217,57.43582615383093,-78.97439564107322
|
48
|
+
c-40.32617769227136,-22.694017358868905,-46.757061615423254,-10.478899461467563,-109.74353110771835,-21.53839897424041
|
49
|
+
c42.65456538984108,-37.726172794888726,207.59033528726195,-161.09545651288613,250.25639615380942,-265.6410794871937
|
50
|
+
c59.076290040109825,88.27497837399585,71.65445633351851,324.2269786926548,-2.051314102583092,434.871755473455
|
51
|
+
c-10.116031236063236,-44.227132350911916,-43.09869935336155,-84.09163111133012,-55.38462128203264,-96.41016701191643
|
52
|
+
c-29.72181832173783,50.24559976029536,-81.95636499161674,115.57349732649573,-102.56403256410249,133.33330897435894
|
53
|
+
c28.623098711290822,72.11880743166671,-7.261530212306525,225.5893488434565,-68.71791375372572,185.6409501984151
|
54
|
+
c-49.148681325965754,-15.333037922763424,18.549622107753976,-115.55505291498798,-7.1795841949922306,-107.69228609585093
|
55
|
+
c-34.95998148195349,19.14481910912764,-167.90750204829328,129.20795509976756,-209.2307092307692,137.43596153846147
|
56
|
+
c-134.6565200483485,-54.336144923914844,-317.1862187488996,-216.49730227173723,-389.7436059656784,-330.25645686152825
|
57
|
+
c-38.71123409937445,37.01014857710106,-36.91255822003268,64.9171844290704,-48.205166417233386,92.30767560666914
|
58
|
+
c-55.39517986825638,-51.583890538004425,-94.67406936751138,-281.75614280779905,-29.74354259488905,-429.7435328612896
|
59
|
+
c18.77666857831457,47.91013041235192,164.53935578109724,200.61765517975073,269.7436206767652,257.4359318084928
|
60
|
+
c-64.02654995017485,6.5618535897069705,-112.85686466785285,11.954077594442651,-115.8975015964005,26.666604615348206
|
61
|
+
c13.369607980979595,27.020215106261958,110.16860728422273,133.64035296812426,184.61540871794875,151.7948817948718
|
62
|
+
c38.54936064125013,-35.17882824956223,61.75817892673331,-120.13381382049238,62.564074222199,-170.2563782051027
|
63
|
+
c-112.01461673846143,-68.58411333497293,-195.4475277093784,-202.73504102566642,21.538517829083048,-313.8462020513076
|
64
|
+
c-0.44986397943876,-39.31628256413069,3.6634418754476883,-100.03343099000347,-4.10254271451231,-111.79488372654134
|
65
|
+
c-172.89423135404945,-4.5819764834471925,-241.96276383285397,15.050453377662961,-246.15389305299936,-45.1281958802341
|
66
|
+
c-1.1141929951265865,-65.30684495420007,65.9235006844765,-60.74779963470837,241.02560210253228,-73.84616725825663" />
|
67
|
+
SVG
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
@@ -4,21 +4,27 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
module Icons
|
10
|
+
class Binoculars
|
11
|
+
def initialize(type: :d)
|
12
|
+
@color = case type
|
13
|
+
when :d
|
14
|
+
USPSFlags::Config::RED
|
15
|
+
when :n
|
16
|
+
USPSFlags::Config::BLUE
|
17
|
+
end
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def svg
|
21
|
+
<<~SVG
|
22
|
+
<polyline fill="#{@color}" points="700 1500 760 600 825 600 825 540 760 540 760 480 1030 480 1030 540 965 540 965 600 1030 600 1090 1500" />
|
23
|
+
<polyline fill="#{@color}" transform="translate(660)" points="700 1500 760 600 825 600 825 540 760 540 760 480 1030 480 1030 540 965 540 965 600 1030 600 1090 1500" />
|
24
|
+
<polyline fill="#{@color}" points="1000 690 1150 690 1150 660 1300 660 1300 690 1450 690 1450 740 1275 740 1275 1380 1390 1380 1390 1430 1060 1430 1060 1380 1175 1380 1175 740 1000 740"/>
|
25
|
+
SVG
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
@@ -4,28 +4,34 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
module Icons
|
10
|
+
class Lighthouse
|
11
|
+
def svg
|
12
|
+
<<~SVG
|
13
|
+
<mask id="lighthouse-mask">
|
14
|
+
<g>
|
15
|
+
<rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
|
16
|
+
<rect x="1150" y="540" fill="#000000" width="80" height="140" />
|
17
|
+
<rect x="1270" y="540" fill="#000000" width="80" height="140" />
|
18
|
+
<polyline fill="#000000" points="1065 690 1065 725 1075 725 1095 710 1095 690" />
|
19
|
+
<polyline fill="#000000" points="1405 690 1435 690 1435 725 1425 725 1405 710" />
|
20
|
+
<polyline fill="#000000" points="1065 760 1065 790 1085 775 1085 760" />
|
21
|
+
<polyline fill="#000000" points="1435 760 1415 760 1415 775 1435 790" />
|
22
|
+
</g>
|
23
|
+
</mask>
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
<g mask="url(#lighthouse-mask)">
|
26
|
+
<polyline fill="#{USPSFlags::Config::RED}" points="1100 475 1100 450 1200 400 1200 350 1300 350 1300 400 1400 450 1400 475" />
|
27
|
+
<polyline fill="#{USPSFlags::Config::RED}" points="1050 800 1050 675 1100 675 1100 500 1400 500 1400 675 1450 675 1450 800" />
|
28
|
+
<polyline fill="#{USPSFlags::Config::RED}" points="1050 825 1075 875 1425 875 1450 825" />
|
29
|
+
<polyline fill="#{USPSFlags::Config::RED}" points="900 1500 1075 900 1425 900 1600 1500" />
|
30
|
+
<polyline fill="#{USPSFlags::Config::RED}" points="900 1525 925 1575 1575 1575 1600 1525" />
|
31
|
+
</g>
|
32
|
+
SVG
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
@@ -4,23 +4,29 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
module Icons
|
10
|
+
class Star
|
11
|
+
def svg
|
12
|
+
svg = "<path d=\"M 0 0\n"
|
13
|
+
points.each { |x, y| svg << "l #{x} #{y}\n" }
|
14
|
+
svg << "\" fill=\"#FFFFFF\" />\n"
|
12
15
|
|
13
|
-
|
14
|
-
|
16
|
+
svg
|
17
|
+
end
|
15
18
|
|
16
|
-
private
|
19
|
+
private
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def points
|
22
|
+
[
|
23
|
+
[117.555, 81.805], [-41.47, -137.085], [114.125, -86.525],
|
24
|
+
[-143.185, -2.915], [-47.025, -135.28], [-47.025, 135.28],
|
25
|
+
[-143.185, 2.915], [114.125, 86.525], [-41.47, 137.085],
|
26
|
+
[117.555, -81.805]
|
27
|
+
]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
@@ -4,133 +4,142 @@
|
|
4
4
|
#
|
5
5
|
# This class should never need to be called directly.
|
6
6
|
# @private
|
7
|
-
class USPSFlags
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
7
|
+
class USPSFlags
|
8
|
+
class Core
|
9
|
+
module Icons
|
10
|
+
class Trident
|
11
|
+
require 'usps_flags/core/icons/trident_parts/hashes'
|
12
|
+
include USPSFlags::Core::Icons::TridentParts::Hashes
|
13
|
+
|
14
|
+
def initialize(type, color: :blue, field_color: nil)
|
15
|
+
valid_types = %i[s d stf n]
|
16
|
+
raise "Error: Invalid trident type. Options are #{valid_types}." unless valid_types.include?(type)
|
17
|
+
|
18
|
+
@type = type
|
19
|
+
|
20
|
+
@trident_config = USPSFlags.configuration.trident
|
21
|
+
load_measures
|
22
|
+
load_measures_from_top
|
23
|
+
load_main_length
|
24
|
+
configure_trident_segments
|
25
|
+
configure_colors(color, field_color)
|
26
|
+
end
|
27
|
+
|
28
|
+
def svg
|
29
|
+
svg = +''
|
30
|
+
svg << '<g mask="url(#delta-mask)">' if @type == :d
|
31
|
+
svg << '<g mask="url(#circle-mask-for-main-spike)">' if @type == :stf
|
32
|
+
@trident_segments.each { |seg| svg << add_trident_segment(seg) }
|
33
|
+
svg << '</g>' if %i[d stf].include?(@type)
|
34
|
+
svg << add_hash
|
35
|
+
|
36
|
+
svg
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def add_trident_segment(segment)
|
42
|
+
svg = +''
|
43
|
+
start = segment.keys.first
|
44
|
+
points = segment.values.first
|
45
|
+
svg << "<path d=\"M #{start[0]} #{start[1]}\n"
|
46
|
+
points.each { |x, y| svg << "l #{x} #{y}\n" }
|
47
|
+
svg << "\" fill=\"#{@color_code}\" />\n"
|
48
|
+
svg
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_hash
|
52
|
+
return delta_hash if @type == :d
|
53
|
+
return circle_hash if @type == :stf
|
54
|
+
|
55
|
+
standard_hash
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_measures
|
59
|
+
@main_spike_overhang = @trident_config[:bar_width] / 2
|
60
|
+
@side_spike_overhang = @trident_config[:bar_width] / 2
|
61
|
+
@top_point = ((USPSFlags::Config::BASE_HOIST - @trident_config[:height][@type]) / 2)
|
62
|
+
end
|
63
|
+
|
64
|
+
def load_measures_from_top
|
65
|
+
@crossbar_top = @top_point + @trident_config[:crossbar_from_top]
|
66
|
+
@hash_from_top = @trident_config[:crossbar_from_top] + (@trident_config[:bar_width] * 2)
|
67
|
+
|
68
|
+
height = @trident_config[:bar_width] * 123 / 128 + @trident_config[:width] / 2
|
69
|
+
@circle_from_top = @trident_config[:crossbar_from_top] + height
|
70
|
+
end
|
71
|
+
|
72
|
+
def load_main_length
|
73
|
+
point = @trident_config[:center_point_height] - @trident_config[:main_point_barb]
|
74
|
+
@main_length = @trident_config[:height][@type] - point
|
75
|
+
end
|
76
|
+
|
77
|
+
def configure_trident_segments
|
78
|
+
@trident_segments = [main_spike, crossbar, left_spike, right_spike]
|
79
|
+
@lower_hash = [
|
80
|
+
[@trident_config[:hash_width], 0], [0, @trident_config[:bar_width]],
|
81
|
+
[-@trident_config[:hash_width], 0], [0, -@trident_config[:bar_width]]
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
85
|
+
def main_spike
|
86
|
+
{
|
87
|
+
[@trident_config[:center_point], @top_point] =>
|
88
|
+
[
|
89
|
+
[@trident_config[:bar_width], @trident_config[:center_point_height]],
|
90
|
+
[-@main_spike_overhang, -@trident_config[:main_point_barb]],
|
91
|
+
[0, @main_length], [-(@trident_config[:bar_width]), 0], [0, -@main_length],
|
92
|
+
[-@main_spike_overhang, @trident_config[:main_point_barb]],
|
93
|
+
[@trident_config[:bar_width], -@trident_config[:center_point_height]]
|
94
|
+
]
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def crossbar
|
99
|
+
{
|
100
|
+
[(@trident_config[:center_point] - @trident_config[:width] / 2), @crossbar_top] =>
|
101
|
+
[
|
102
|
+
[@trident_config[:width], 0], [0, @trident_config[:bar_width]],
|
103
|
+
[-@trident_config[:width], 0], [0, -@trident_config[:bar_width]]
|
104
|
+
]
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def left_spike
|
109
|
+
{
|
110
|
+
[(@trident_config[:center_point] - @trident_config[:width] / 2), (@crossbar_top + 1)] =>
|
111
|
+
[
|
112
|
+
[0, -(@trident_config[:side_spike_height] + @trident_config[:side_point_height])],
|
113
|
+
[(@trident_config[:bar_width] + @side_spike_overhang), @trident_config[:side_point_height]],
|
114
|
+
[-@side_spike_overhang, 0], [0, @trident_config[:side_spike_height]]
|
115
|
+
]
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def right_spike
|
120
|
+
{
|
121
|
+
[(@trident_config[:center_point] + @trident_config[:width] / 2), (@crossbar_top + 1)] =>
|
122
|
+
[
|
123
|
+
[0, -(@trident_config[:side_spike_height] + @trident_config[:side_point_height])],
|
124
|
+
[-(@trident_config[:bar_width] + @side_spike_overhang), @trident_config[:side_point_height]],
|
125
|
+
[@side_spike_overhang, 0], [0, @trident_config[:side_spike_height]]
|
126
|
+
]
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
def configure_colors(color, field_color)
|
131
|
+
@color_code = '#FFFFFF'
|
132
|
+
if color == :red
|
133
|
+
@color_code, @field_color_code = [USPSFlags::Config::RED, '#FFFFFF']
|
134
|
+
elsif color == :blue
|
135
|
+
@color_code, @field_color_code = [USPSFlags::Config::BLUE, '#FFFFFF']
|
136
|
+
elsif field_color == :red
|
137
|
+
@field_color_code = USPSFlags::Config::RED
|
138
|
+
elsif field_color == :blue
|
139
|
+
@field_color_code = USPSFlags::Config::BLUE
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
134
143
|
end
|
135
144
|
end
|
136
145
|
end
|