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,66 +4,73 @@
4
4
  #
5
5
  # These methods should never need to be called directly.
6
6
  # @private
7
- module USPSFlags::Core::Icons::TridentParts
8
- module Hashes
9
- def delta_hash
10
- <<~SVG
11
- <polyline mask="url(#delta-mask)" fill="#{@color_code}" points="#{delta_mask_points(@trident_config[:center_point], @trident_config[:height][:d], @trident_config[:delta_from_bottom])}" />
12
- <mask id="delta-mask">
13
- <g>
14
- <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
15
- <polyline transform="scale(#{@trident_config[:delta_gap_scale]}) translate(#{@trident_config[:delta_gap_x]},#{@trident_config[:delta_gap_y]})" fill="#000000" points="#{delta_points(@trident_config[:center_point], @trident_config[:height][:d], @trident_config[:delta_from_bottom])}" />
16
- </g>
17
- </mask>
18
- SVG
19
- end
7
+ class USPSFlags
8
+ class Core
9
+ module Icons
10
+ class TridentParts
11
+ module Hashes
12
+ def delta_hash
13
+ <<~SVG
14
+ <polyline mask="url(#delta-mask)" fill="#{@color_code}" points="#{delta_mask_points(@trident_config[:center_point], @trident_config[:height][:d], @trident_config[:delta_from_bottom])}" />
15
+ <mask id="delta-mask">
16
+ <g>
17
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
18
+ <polyline transform="scale(#{@trident_config[:delta_gap_scale]}) translate(#{@trident_config[:delta_gap_x]},#{@trident_config[:delta_gap_y]})" fill="#000000" points="#{delta_points(@trident_config[:center_point], @trident_config[:height][:d], @trident_config[:delta_from_bottom])}" />
19
+ </g>
20
+ </mask>
21
+ SVG
22
+ end
20
23
 
21
- def delta_mask_points(center, height, bottom)
22
- top = @top_point + height - bottom
23
- <<~SVG
24
- #{center}, #{top - @trident_config[:delta_height]}
25
- #{center + @trident_config[:width] / 2}, #{top}
26
- #{center - @trident_config[:width] / 2}, #{top}
27
- #{center}, #{top - @trident_config[:delta_height]}
28
- SVG
29
- end
24
+ def delta_mask_points(center, height, bottom)
25
+ top = @top_point + height - bottom
26
+ <<~SVG
27
+ #{center}, #{top - @trident_config[:delta_height]}
28
+ #{center + @trident_config[:width] / 2}, #{top}
29
+ #{center - @trident_config[:width] / 2}, #{top}
30
+ #{center}, #{top - @trident_config[:delta_height]}
31
+ SVG
32
+ end
30
33
 
31
- def delta_points(center, height, bottom)
32
- top = @top_point + height - bottom - @trident_config[:delta_height]
33
- mid = @top_point + height - bottom * 17 / 20
34
- <<~SVG
35
- #{center}, #{top}
36
- #{center + @trident_config[:width] / 2}, #{mid}
37
- #{center - @trident_config[:width] / 2}, #{mid}
38
- #{center}, #{top}
39
- SVG
40
- end
34
+ def delta_points(center, height, bottom)
35
+ top = @top_point + height - bottom - @trident_config[:delta_height]
36
+ mid = @top_point + height - bottom * 17 / 20
37
+ <<~SVG
38
+ #{center}, #{top}
39
+ #{center + @trident_config[:width] / 2}, #{mid}
40
+ #{center - @trident_config[:width] / 2}, #{mid}
41
+ #{center}, #{top}
42
+ SVG
43
+ end
41
44
 
42
- def circle_hash
43
- center = @trident_config[:center_point]
44
- <<~SVG
45
- <circle cx="#{center}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width] / 2}" fill="#{@color_code}" mask="url(#circle-mask)" />
46
- <mask id="circle-mask">
47
- <g>
48
- <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
49
- <circle cx="#{center}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width] / 2 - @trident_config[:bar_width]}" fill="#000000" />
50
- </g>
51
- </mask>
52
- <mask id="circle-mask-for-main-spike">
53
- <g transform="scale(1.05) translate(-@trident_config[:br_width], -@trident_config[:br_width]/2)">
54
- <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
55
- <circle cx="#{center}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width] / 2 - @trident_config[:bar_width]}" fill="#000000" />
56
- </g>
57
- </mask>
58
- SVG
59
- end
45
+ def circle_hash
46
+ center = @trident_config[:center_point]
47
+ <<~SVG
48
+ <circle cx="#{center}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width] / 2}" fill="#{@color_code}" mask="url(#circle-mask)" />
49
+ <mask id="circle-mask">
50
+ <g>
51
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
52
+ <circle cx="#{center}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width] / 2 - @trident_config[:bar_width]}" fill="#000000" />
53
+ </g>
54
+ </mask>
55
+ <mask id="circle-mask-for-main-spike">
56
+ <g transform="scale(1.05) translate(-@trident_config[:br_width], -@trident_config[:br_width]/2)">
57
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
58
+ <circle cx="#{center}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width] / 2 - @trident_config[:bar_width]}" fill="#000000" />
59
+ </g>
60
+ </mask>
61
+ SVG
62
+ end
60
63
 
61
- def standard_hash
62
- svg = "<path d=\"M #{(@trident_config[:center_point] - @trident_config[:hash_width] / 2)} #{(@top_point + @hash_from_top)}\n"
63
- @lower_hash.each { |x, y| svg << "l #{x} #{y}\n" }
64
- svg << "\" fill=\"#{@color_code}\" />\n"
64
+ def standard_hash
65
+ x_pos = (@trident_config[:center_point] - @trident_config[:hash_width] / 2)
66
+ svg = "<path d=\"M #{x_pos} #{(@top_point + @hash_from_top)}\n"
67
+ @lower_hash.each { |x, y| svg << "l #{x} #{y}\n" }
68
+ svg << "\" fill=\"#{@color_code}\" />\n"
65
69
 
66
- svg
70
+ svg
71
+ end
72
+ end
73
+ end
67
74
  end
68
75
  end
69
76
  end
@@ -4,36 +4,42 @@
4
4
  #
5
5
  # This class should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core::Icons::Trumpet
8
- def initialize(type: :s)
9
- @color = type == :n ? USPSFlags::Config::BLUE : USPSFlags::Config::RED
10
- @count = type == :s ? 1 : 2
11
- end
7
+ class USPSFlags
8
+ class Core
9
+ module Icons
10
+ class Trumpet
11
+ def initialize(type: :s)
12
+ @color = type == :n ? USPSFlags::Config::BLUE : USPSFlags::Config::RED
13
+ @count = type == :s ? 1 : 2
14
+ end
12
15
 
13
- def svg
14
- if @count == 2
15
- <<~SVG
16
- <g transform="translate(1100,-600)"><g transform="rotate(45)">#{trumpet}</g></g>
17
- <g transform="translate(-300,1100)"><g transform="rotate(-45)">#{trumpet}</g></g>
18
- SVG
19
- else
20
- trumpet
21
- end
22
- end
16
+ def svg
17
+ if @count == 2
18
+ <<~SVG
19
+ <g transform="translate(1100,-600)"><g transform="rotate(45)">#{trumpet}</g></g>
20
+ <g transform="translate(-300,1100)"><g transform="rotate(-45)">#{trumpet}</g></g>
21
+ SVG
22
+ else
23
+ trumpet
24
+ end
25
+ end
23
26
 
24
- private
27
+ private
25
28
 
26
- def trumpet
27
- <<~SVG
28
- <path d="M1139.9999958974363,480.00000000000006
29
- c-44.15476410256406,-6.5910035897434796,-116.84910635897381,-20.41065056410247,-114.87185282051291,-47.179479230769175
30
- c4.028547230769618,-65.74318056410249,367.85434817948703,-61.23149248717954,369.23087128205134,-2.051282051282101
31
- c-4.777324897435847,30.46226187179502,-55.229016102563946,41.4042592820515,-114.87183128205106,49.230751282051415
32
- c20.35720646153868,375.0059741538461,27.19074102564059,490.4570292564102,53.33331769230767,1003.0769130769231
33
- c87.68105358974367,28.51730900000007,159.61708317948705,60.951568051282266,231.79492435897487,145.6410723076924
34
- c-309.3606388717951,-1.4643622051280545,-403.6171671794875,0.35877820512882863,-709.7436194871801,-2.0512861538461493
35
- c106.18124384615362,-96.7690410256414,99.88082358974339,-91.1716969230772,229.74356769230792,-141.53843102564088"
36
- fill="#{@color}" />
37
- SVG
29
+ def trumpet
30
+ <<~SVG
31
+ <path d="M1139.9999958974363,480.00000000000006
32
+ c-44.15476410256406,-6.5910035897434796,-116.84910635897381,-20.41065056410247,-114.87185282051291,-47.179479230769175
33
+ c4.028547230769618,-65.74318056410249,367.85434817948703,-61.23149248717954,369.23087128205134,-2.051282051282101
34
+ c-4.777324897435847,30.46226187179502,-55.229016102563946,41.4042592820515,-114.87183128205106,49.230751282051415
35
+ c20.35720646153868,375.0059741538461,27.19074102564059,490.4570292564102,53.33331769230767,1003.0769130769231
36
+ c87.68105358974367,28.51730900000007,159.61708317948705,60.951568051282266,231.79492435897487,145.6410723076924
37
+ c-309.3606388717951,-1.4643622051280545,-403.6171671794875,0.35877820512882863,-709.7436194871801,-2.0512861538461493
38
+ c106.18124384615362,-96.7690410256414,99.88082358974339,-91.1716969230772,229.74356769230792,-141.53843102564088"
39
+ fill="#{@color}" />
40
+ SVG
41
+ end
42
+ end
43
+ end
38
44
  end
39
45
  end
@@ -4,51 +4,55 @@
4
4
  #
5
5
  # This class should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core::Pennant
8
- def initialize(type: :cruise)
9
- @type = type.to_s.upcase
10
- @fly = USPSFlags::Config::BASE_FLY
11
- @hoist = USPSFlags::Config::BASE_HOIST / 4
12
- end
13
-
14
- def svg
15
- return oic if @type == 'OIC'
16
- return cruise if @type == 'CRUISE'
17
- end
18
-
19
- private
20
-
21
- def oic
22
- <<~SVG
23
- <polyline fill="#{USPSFlags::Config::BLUE}" points="0 0 #{USPSFlags::Config::BASE_FLY} #{USPSFlags::Config::BASE_HOIST / 8} 0 #{USPSFlags::Config::BASE_HOIST / 4}" />
24
- SVG
25
- end
26
-
27
- def cruise
28
- <<~SVG
29
- #{cruise_red}#{cruise_white}#{cruise_blue}
30
- <path d="M 0 0 l #{@fly} #{@hoist / 2} l -#{@fly} #{@hoist / 2}" fill="none" stroke="#000000" stroke-width="2" />
31
- <g transform=\"translate(385, 340)\">
32
- #{USPSFlags::Core.star}
33
- </g>"
34
- SVG
35
- end
36
-
37
- def cruise_red
38
- <<~SVG
39
- <path d="M 0 0 l #{@fly * 10 / 36} #{@hoist * 5 / 36} l 0 #{@hoist * 26 / 36} l -#{@fly * 10 / 36} #{@hoist * 5 / 36}" fill="#{USPSFlags::Config::RED}" />
40
- SVG
41
- end
42
-
43
- def cruise_white
44
- <<~SVG
45
- <path d="M #{@fly * 10 / 36} #{@hoist * 5 / 36} l #{@fly * 11 / 36} #{@hoist * 5.5 / 36} l 0 #{@hoist * 15 / 36} l -#{@fly * 11 / 36} #{@hoist * 5.5 / 36}" fill="#FFFFFF" />
46
- SVG
47
- end
48
-
49
- def cruise_blue
50
- <<~SVG
51
- <path d="M #{@fly * 21 / 36} #{@hoist * 10.5 / 36} l #{@fly * 15 / 36} #{@hoist * 7.5 / 36} l -#{@fly * 15 / 36} #{@hoist * 7.5 / 36}" fill="#{USPSFlags::Config::BLUE}" />
52
- SVG
7
+ class USPSFlags
8
+ class Core
9
+ class Pennant
10
+ def initialize(type: :cruise)
11
+ @type = type.to_s.upcase
12
+ @fly = USPSFlags::Config::BASE_FLY
13
+ @hoist = USPSFlags::Config::BASE_HOIST / 4
14
+ end
15
+
16
+ def svg
17
+ return oic if @type == 'OIC'
18
+ return cruise if @type == 'CRUISE'
19
+ end
20
+
21
+ private
22
+
23
+ def oic
24
+ <<~SVG
25
+ <polyline fill="#{USPSFlags::Config::BLUE}" points="0 0 #{USPSFlags::Config::BASE_FLY} #{USPSFlags::Config::BASE_HOIST / 8} 0 #{USPSFlags::Config::BASE_HOIST / 4}" />
26
+ SVG
27
+ end
28
+
29
+ def cruise
30
+ <<~SVG
31
+ #{cruise_red}#{cruise_white}#{cruise_blue}
32
+ <path d="M 0 0 l #{@fly} #{@hoist / 2} l -#{@fly} #{@hoist / 2}" fill="none" stroke="#000000" stroke-width="2" />
33
+ <g transform=\"translate(385, 340)\">
34
+ #{USPSFlags::Core.star}
35
+ </g>"
36
+ SVG
37
+ end
38
+
39
+ def cruise_red
40
+ <<~SVG
41
+ <path d="M 0 0 l #{@fly * 10 / 36} #{@hoist * 5 / 36} l 0 #{@hoist * 26 / 36} l -#{@fly * 10 / 36} #{@hoist * 5 / 36}" fill="#{USPSFlags::Config::RED}" />
42
+ SVG
43
+ end
44
+
45
+ def cruise_white
46
+ <<~SVG
47
+ <path d="M #{@fly * 10 / 36} #{@hoist * 5 / 36} l #{@fly * 11 / 36} #{@hoist * 5.5 / 36} l 0 #{@hoist * 15 / 36} l -#{@fly * 11 / 36} #{@hoist * 5.5 / 36}" fill="#FFFFFF" />
48
+ SVG
49
+ end
50
+
51
+ def cruise_blue
52
+ <<~SVG
53
+ <path d="M #{@fly * 21 / 36} #{@hoist * 10.5 / 36} l #{@fly * 15 / 36} #{@hoist * 7.5 / 36} l -#{@fly * 15 / 36} #{@hoist * 7.5 / 36}" fill="#{USPSFlags::Config::BLUE}" />
54
+ SVG
55
+ end
56
+ end
53
57
  end
54
58
  end
@@ -4,137 +4,141 @@
4
4
  #
5
5
  # This class should never need to be called directly.
6
6
  # @private
7
- class USPSFlags::Core::TridentSpec
8
- SA = USPSFlags::Helpers::SpecArrows
9
- BF = USPSFlags::Config::BASE_FLY
10
- BH = USPSFlags::Config::BASE_HOIST
11
-
12
- def initialize(fly: 24, unit: 'in', scaled_border: false)
13
- @config = USPSFlags.configuration.trident
14
- @scaled_border = scaled_border
15
- configure_sizes(fly)
16
- configure_labels(unit)
17
- end
18
-
19
- def svg
20
- svg = spec_header
21
- svg << add_short_trident
22
- svg << add_delta_trident
23
- svg << add_national_tridents
24
-
25
- svg
26
- end
27
-
28
- private
29
-
30
- def box_left
31
- (BF * 27 / 32) / 2
32
- end
33
-
34
- def box_right
35
- (BF * 37 / 32) / 2
36
- end
37
-
38
- def add_short_trident
39
- box_top = BH / 4
40
- box_bottom = BH * 3 / 4
41
- add_trident(:Short, box_top, box_bottom, box_left, box_right)
42
- end
43
-
44
- def add_delta_trident
45
- box_top = BH * 3 / 16
46
- box_bottom = BH * 13 / 16
47
- add_trident(:Delta, box_top, box_bottom, box_left, box_right)
48
- end
49
-
50
- def add_national_tridents
51
- box_top = BH / 8
52
- box_bottom = BH * 7 / 8
53
- add_trident(:Circle, box_top, box_bottom, box_left, box_right) +
54
- add_trident(:Long, box_top, box_bottom, box_left, box_right)
55
- end
56
-
57
- def configure_sizes(fly)
58
- @fly = Rational(fly)
59
- get_hoist_from_fly(@fly)
60
- configure_hoist_fraction
61
- configure_fly_fraction
62
- end
63
-
64
- def get_hoist_from_fly(fly)
65
- hoist = (fly * Rational(2, 3))
66
- @hoist = if hoist == hoist.to_i
67
- hoist.to_i
68
- else
69
- hoist
70
- end
71
- end
72
-
73
- def configure_hoist_fraction
74
- @hoist_fraction = ''
75
- if @hoist == @hoist.to_i
76
- @hoist = @hoist.to_i
77
- else
78
- @hoist, @hoist_fraction = @hoist.to_simplified_a
79
- end
80
- end
81
-
82
- def configure_fly_fraction
83
- @fly_fraction = ''
84
- if @fly == @fly.to_i
85
- @fly = @fly.to_i
86
- else
87
- @fly, @fly_fraction = @fly.to_simplified_a
88
- end
89
- end
90
-
91
- def configure_labels(unit)
92
- @label_font_size = if Math.sqrt(@fly) > 24
93
- BF * Math.log(24, Math.sqrt(@fly)) / 60
94
- else
95
- BF / 60
96
- end
97
-
98
- @unit_text = unit.nil? ? '' : "#{unit}"
99
- @unit = unit
100
-
101
- configure_barb_label
102
- end
103
-
104
- def configure_barb_label
105
- barb_label = Rational(@config[:main_point_barb]) * @fly / BF
106
- @barb_label = if barb_label == barb_label.to_i
107
- "#{barb_label.to_i}#{@unit_text}"
108
- else
109
- "#{barb_label.to_simplified_s}#{@unit_text}"
7
+ class USPSFlags
8
+ class Core
9
+ class TridentSpec
10
+ SA = USPSFlags::Helpers::SpecArrows
11
+ BF = USPSFlags::Config::BASE_FLY
12
+ BH = USPSFlags::Config::BASE_HOIST
13
+
14
+ def initialize(fly: 24, unit: 'in', scaled_border: false)
15
+ @config = USPSFlags.configuration.trident
16
+ @scaled_border = scaled_border
17
+ configure_sizes(fly)
18
+ configure_labels(unit)
19
+ end
20
+
21
+ def svg
22
+ svg = spec_header
23
+ svg << add_short_trident
24
+ svg << add_delta_trident
25
+ svg << add_national_tridents
26
+
27
+ svg
28
+ end
29
+
30
+ private
31
+
32
+ def box_left
33
+ (BF * 27 / 32) / 2
34
+ end
35
+
36
+ def box_right
37
+ (BF * 37 / 32) / 2
38
+ end
39
+
40
+ def add_short_trident
41
+ box_top = BH / 4
42
+ box_bottom = BH * 3 / 4
43
+ add_trident(:Short, box_top, box_bottom, box_left, box_right)
44
+ end
45
+
46
+ def add_delta_trident
47
+ box_top = BH * 3 / 16
48
+ box_bottom = BH * 13 / 16
49
+ add_trident(:Delta, box_top, box_bottom, box_left, box_right)
50
+ end
51
+
52
+ def add_national_tridents
53
+ box_top = BH / 8
54
+ box_bottom = BH * 7 / 8
55
+ add_trident(:Circle, box_top, box_bottom, box_left, box_right) +
56
+ add_trident(:Long, box_top, box_bottom, box_left, box_right)
57
+ end
58
+
59
+ def configure_sizes(fly)
60
+ @fly = Rational(fly)
61
+ get_hoist_from_fly(@fly)
62
+ configure_hoist_fraction
63
+ configure_fly_fraction
64
+ end
65
+
66
+ def get_hoist_from_fly(fly)
67
+ hoist = (fly * Rational(2, 3))
68
+ @hoist = if hoist == hoist.to_i
69
+ hoist.to_i
70
+ else
71
+ hoist
72
+ end
73
+ end
74
+
75
+ def configure_hoist_fraction
76
+ @hoist_fraction = ''
77
+ if @hoist == @hoist.to_i
78
+ @hoist = @hoist.to_i
79
+ else
80
+ @hoist, @hoist_fraction = USPSFlags::Rational.new(@hoist).to_simplified_a
81
+ end
82
+ end
83
+
84
+ def configure_fly_fraction
85
+ @fly_fraction = ''
86
+ if @fly == @fly.to_i
87
+ @fly = @fly.to_i
88
+ else
89
+ @fly, @fly_fraction = USPSFlags::Rational.new(@fly).to_simplified_a
90
+ end
91
+ end
92
+
93
+ def configure_labels(unit)
94
+ @label_font_size = if Math.sqrt(@fly) > 24
95
+ BF * Math.log(24, Math.sqrt(@fly)) / 60
96
+ else
97
+ BF / 60
98
+ end
99
+
100
+ @unit_text = unit.nil? ? '' : unit.to_s
101
+ @unit = unit
102
+
103
+ configure_barb_label
104
+ end
105
+
106
+ def configure_barb_label
107
+ barb_label = Rational(@config[:main_point_barb]) * @fly / BF
108
+ @barb_label = if barb_label == barb_label.to_i
109
+ "#{barb_label.to_i}#{@unit_text}"
110
+ else
111
+ "#{USPSFlags::Rational.new(barb_label).to_simplified_s}#{@unit_text}"
112
+ end
113
+ end
114
+
115
+ def spec_header
116
+ USPSFlags::Core::TridentSpecs::Header.new(
117
+ fly: @fly, fly_fraction: @fly_fraction, hoist: @hoist, hoist_fraction: @hoist_fraction,
118
+ unit_text: @unit_text, scaled_border: @scaled_border
119
+ ).p
120
+ end
121
+
122
+ def add_trident(type, box_top, box_bottom, box_left, box_right)
123
+ sym = { Short: :s, Delta: :d, Circle: :stf, Long: :n }[type]
124
+
125
+ Object.const_get("USPSFlags::Core::TridentSpecs::#{type}").new(
126
+ bt: box_top, bb: box_bottom, bl: box_left, br: box_right,
127
+ fly: @fly, unit: @unit, heading: heading(sym), config: @config
128
+ ).p
129
+ end
130
+
131
+ def heading(type_sym)
132
+ type, description = {
133
+ s: ['Short', 'Squadron Officers'], d: ['Delta', 'District Officers'],
134
+ stf: ['Circle', 'Staff Commanders Only'], n: ['Long', 'National Officers']
135
+ }[type_sym]
136
+
137
+ <<~SVG
138
+ <text x="#{BF / 2}" y="#{BH * 1 / 40}" font-family="sans-serif" font-size="#{BH / 30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">#{type}</text>
139
+ <text x="#{BF / 2}" y="#{BH * 5 / 80}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#BF0D3E" text-anchor="middle">#{description}</text>
140
+ SVG
141
+ end
110
142
  end
111
143
  end
112
-
113
- def spec_header
114
- USPSFlags::Core::TridentSpecs::Header.new(
115
- fly: @fly, fly_fraction: @fly_fraction, hoist: @hoist, hoist_fraction: @hoist_fraction,
116
- unit_text: @unit_text, scaled_border: @scaled_border
117
- ).p
118
- end
119
-
120
- def add_trident(type, box_top, box_bottom, box_left, box_right)
121
- sym = { Short: :s, Delta: :d, Circle: :stf, Long: :n }[type]
122
-
123
- Object.const_get("USPSFlags::Core::TridentSpecs::#{type}").new(
124
- bt: box_top, bb: box_bottom, bl: box_left, br: box_right,
125
- fly: @fly, unit: @unit, heading: heading(sym), config: @config
126
- ).p
127
- end
128
-
129
- def heading(type_sym)
130
- type, description = {
131
- s: ['Short', 'Squadron Officers'], d: ['Delta', 'District Officers'],
132
- stf: ['Circle', 'Staff Commanders Only'], n: ['Long', 'National Officers']
133
- }[type_sym]
134
-
135
- <<~SVG
136
- <text x="#{BF / 2}" y="#{BH * 1 / 40}" font-family="sans-serif" font-size="#{BH / 30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">#{type}</text>
137
- <text x="#{BF / 2}" y="#{BH * 5 / 80}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#BF0D3E" text-anchor="middle">#{description}</text>
138
- SVG
139
- end
140
144
  end