usps_flags 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a401780854a7517c7b211d59ae8c64d99f2190ece54927c9db84fea2bf33957
4
- data.tar.gz: cd332320e247bd219bf094a72ab6c31a57fb642fefdc3cab889a4fb26b32cfc4
3
+ metadata.gz: 81903e12eb16e794cf65e42f308bac5f1a31eafbec1bdb338de3cf162b3eaa7c
4
+ data.tar.gz: f05fd9c77801a80bb30e0c5e6b94727c1585a6bc2dff316adca65aad11a51eeb
5
5
  SHA512:
6
- metadata.gz: a7d4c6dd949fb0402e768a3347610cf417c2926eddbb99fe319721bb4d09595d2f9886b52bcbb88728dfa6b1d556d839e992e01b4c70a62a0ceef997996f81e4
7
- data.tar.gz: 0d4ab1879a6d9fc1616a8fd7b1532dd50900a824d39b958679fecbc05ab8966a64d8bb48aa5ff505d5a43ce5eb4dd764b030c0063f4fba9e4ced7ab3c1e27ece
6
+ metadata.gz: 3bb2c5d8072a94e5c34d4ab6f45755db623e81be902b6256d20767a6ad6dca3bf5eccccc9c2b2e63bf0f59a16a2726675f9befdc0b86e34192f731b12aefdc7d
7
+ data.tar.gz: a3450ce9bb0fa69b173c52feeb6344d06cee8a2bfb5ff27dfa3eadc955c2022b5387bac647f385bb145de3f7fae903bae52642805eb7b08a507988be958a11b2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.5.1)
4
+ usps_flags (0.5.2)
5
5
  file_utils (~> 1.1, >= 1.1.2)
6
6
  mini_magick (~> 4.8, >= 4.8.0)
7
7
  rubyzip (~> 1.2, >= 1.2.1)
@@ -0,0 +1,24 @@
1
+ usps_flags:
2
+ - rational
3
+ - config
4
+ - configuration
5
+ - helpers
6
+ - core
7
+ - generate
8
+ - errors
9
+ usps_flags/helpers:
10
+ - builders
11
+ - spec_arrows
12
+ usps_flags/core:
13
+ - icons
14
+ - ensign
15
+ - field
16
+ - footer
17
+ - headers
18
+ - pennant
19
+ - tridents
20
+ - trident_specs
21
+ - us
22
+ - wheel
23
+ usps_flags/generate:
24
+ - flag
@@ -5,18 +5,12 @@
5
5
  # @author Julian Fiander
6
6
  # @since 0.1.5
7
7
  class USPSFlags
8
- MODULES ||= {
9
- 'usps_flags' => %w[rational config helpers core generate errors],
10
- 'usps_flags/helpers' => %w[builders spec_arrows],
11
- 'usps_flags/core' => %w[
12
- icons ensign field footer headers pennant tridents trident_specs trident_spec us wheel
13
- ],
14
- 'usps_flags/generate' => %w[flag]
15
- }.freeze
16
-
17
8
  require 'fileutils'
18
9
  require 'zip'
19
10
  require 'mini_magick'
11
+ require 'yaml'
12
+
13
+ MODULES ||= ::YAML.safe_load(File.read('lib/modules.yml')).freeze
20
14
 
21
15
  MODULES.each do |parent, bases|
22
16
  bases.each do |base|
@@ -25,54 +19,8 @@ class USPSFlags
25
19
  end
26
20
  end
27
21
 
28
- # Configuration accessor.
29
- def self.configuration
30
- @configuration ||= USPSFlags::Config.new
31
- end
32
-
33
- # Configuration constructor.
34
- def self.configure
35
- yield(configuration) if block_given?
36
- ensure_directories
37
- @configuration
38
- end
39
-
40
- # Ensures the directory structure exists.
41
- #
42
- # @private
43
- def self.ensure_directories
44
- get_dir_configs
45
- prepare_dir_configs
46
- prepare_flags_dir
47
- ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
48
- end
49
-
50
- # Gets all configuration variables that specify a dir.
51
- #
52
- # @private
53
- def self.get_dir_configs
54
- @dirs = USPSFlags.configuration.instance_variables.map(&:to_s)
55
- .map { |v| v.match(/.*?_dir/) }.compact.map(&:to_s)
56
- end
57
-
58
- # Ensures that directories exist (and are cleared, if configured).
59
- #
60
- # @private
61
- def self.prepare_dir_configs
62
- @dirs.each do |dir|
63
- dir_path = @configuration.instance_variable_get(dir)
64
- ::FileUtils.rm_rf(dir_path) if @configuration.clear
65
- ::FileUtils.mkdir_p(dir_path)
66
- end
67
- end
68
-
69
- # Ensures that the flags_dir subdirectories exist.
70
- #
71
- # @private
72
- def self.prepare_flags_dir
73
- ::FileUtils.mkdir_p("#{@configuration.flags_dir}/PNG/insignia")
74
- ::FileUtils.mkdir_p("#{@configuration.flags_dir}/SVG/insignia")
75
- ::FileUtils.mkdir_p("#{@configuration.flags_dir}/ZIP")
22
+ class << self
23
+ include USPSFlags::Configuration
76
24
  end
77
25
 
78
26
  # Constructor for individual flags.
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: false
2
+
3
+ # User input configuration module.
4
+ class USPSFlags
5
+ module Configuration
6
+ # Configuration accessor.
7
+ def configuration
8
+ @configuration ||= USPSFlags::Config.new
9
+ end
10
+
11
+ # Configuration constructor.
12
+ def configure
13
+ yield(configuration) if block_given?
14
+ ensure_directories
15
+ @configuration
16
+ end
17
+
18
+ # Ensures the directory structure exists.
19
+ #
20
+ # @private
21
+ def ensure_directories
22
+ get_dir_configs
23
+ prepare_dir_configs
24
+ prepare_flags_dir
25
+ ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
26
+ end
27
+
28
+ # Gets all configuration variables that specify a dir.
29
+ #
30
+ # @private
31
+ def get_dir_configs
32
+ @dirs = USPSFlags.configuration.instance_variables.map(&:to_s).map do |v|
33
+ v.match(/.*?_dir/)
34
+ end.compact.map(&:to_s)
35
+ end
36
+
37
+ # Ensures that directories exist (and are cleared, if configured).
38
+ #
39
+ # @private
40
+ def prepare_dir_configs
41
+ @dirs.each do |dir|
42
+ dir_path = @configuration.instance_variable_get(dir)
43
+ ::FileUtils.rm_rf(dir_path) if @configuration.clear
44
+ ::FileUtils.mkdir_p(dir_path)
45
+ end
46
+ end
47
+
48
+ # Ensures that the flags_dir subdirectories exist.
49
+ #
50
+ # @private
51
+ def prepare_flags_dir
52
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/PNG/insignia")
53
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/SVG/insignia")
54
+ ::FileUtils.mkdir_p("#{@configuration.flags_dir}/ZIP")
55
+ end
56
+ end
57
+ end
@@ -7,7 +7,7 @@
7
7
  class USPSFlags
8
8
  class Core
9
9
  def self.trident_spec(fly: 24, unit: 'in', scaled_border: false)
10
- USPSFlags::Core::TridentSpec.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
10
+ USPSFlags::Core::TridentSpecs::Build.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
11
11
  end
12
12
 
13
13
  def self.headers(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
@@ -7,12 +7,17 @@
7
7
  class USPSFlags
8
8
  class Core
9
9
  module TridentSpecs
10
+ SA = USPSFlags::Helpers::SpecArrows
11
+ BF = USPSFlags::Config::BASE_FLY
12
+ BH = USPSFlags::Config::BASE_HOIST
13
+
10
14
  require 'usps_flags/core/trident_specs/base'
11
15
  require 'usps_flags/core/trident_specs/header'
12
16
  require 'usps_flags/core/trident_specs/short'
13
17
  require 'usps_flags/core/trident_specs/delta'
14
18
  require 'usps_flags/core/trident_specs/long'
15
19
  require 'usps_flags/core/trident_specs/circle'
20
+ require 'usps_flags/core/trident_specs/build'
16
21
  end
17
22
  end
18
23
  end
@@ -12,9 +12,9 @@ class USPSFlags
12
12
  require 'usps_flags/core/trident_specs/horizontal'
13
13
  require 'usps_flags/core/trident_specs/overlay'
14
14
 
15
- SA = USPSFlags::Helpers::SpecArrows
16
- BF = USPSFlags::Config::BASE_FLY
17
- BH = USPSFlags::Config::BASE_HOIST
15
+ # SA = USPSFlags::Helpers::SpecArrows
16
+ # BF = USPSFlags::Config::BASE_FLY
17
+ # BH = USPSFlags::Config::BASE_HOIST
18
18
 
19
19
  def initialize(options = {})
20
20
  @config = options[:config]
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: false
2
+
3
+ # Core SVG data for the trident specification sheet.
4
+ #
5
+ # This class should never need to be called directly.
6
+ # @private
7
+ class USPSFlags
8
+ class Core
9
+ module TridentSpecs
10
+ class Build
11
+ def initialize(fly: 24, unit: 'in', scaled_border: false)
12
+ @config = USPSFlags.configuration.trident
13
+ @scaled_border = scaled_border
14
+ configure_sizes(fly)
15
+ configure_labels(unit)
16
+ end
17
+
18
+ def svg
19
+ svg = spec_header
20
+ svg << add_short_trident
21
+ svg << add_delta_trident
22
+ svg << add_national_tridents
23
+
24
+ svg
25
+ end
26
+
27
+ private
28
+
29
+ def box_left
30
+ (BF * 27 / 32) / 2
31
+ end
32
+
33
+ def box_right
34
+ (BF * 37 / 32) / 2
35
+ end
36
+
37
+ def add_short_trident
38
+ box_top = BH / 4
39
+ box_bottom = BH * 3 / 4
40
+ add_trident(:Short, box_top, box_bottom, box_left, box_right)
41
+ end
42
+
43
+ def add_delta_trident
44
+ box_top = BH * 3 / 16
45
+ box_bottom = BH * 13 / 16
46
+ add_trident(:Delta, box_top, box_bottom, box_left, box_right)
47
+ end
48
+
49
+ def add_national_tridents
50
+ box_top = BH / 8
51
+ box_bottom = BH * 7 / 8
52
+ add_trident(:Circle, box_top, box_bottom, box_left, box_right) +
53
+ add_trident(:Long, box_top, box_bottom, box_left, box_right)
54
+ end
55
+
56
+ def configure_sizes(fly)
57
+ @fly = Rational(fly)
58
+ get_hoist_from_fly(@fly)
59
+ configure_hoist_fraction
60
+ configure_fly_fraction
61
+ end
62
+
63
+ def get_hoist_from_fly(fly)
64
+ hoist = (fly * Rational(2, 3))
65
+ @hoist = if hoist == hoist.to_i
66
+ hoist.to_i
67
+ else
68
+ hoist
69
+ end
70
+ end
71
+
72
+ def configure_hoist_fraction
73
+ @hoist_fraction = ''
74
+ if @hoist == @hoist.to_i
75
+ @hoist = @hoist.to_i
76
+ else
77
+ @hoist, @hoist_fraction = USPSFlags::Rational.new(@hoist).to_simplified_a
78
+ end
79
+ end
80
+
81
+ def configure_fly_fraction
82
+ @fly_fraction = ''
83
+ if @fly == @fly.to_i
84
+ @fly = @fly.to_i
85
+ else
86
+ @fly, @fly_fraction = USPSFlags::Rational.new(@fly).to_simplified_a
87
+ end
88
+ end
89
+
90
+ def configure_labels(unit)
91
+ @label_font_size = if Math.sqrt(@fly) > 24
92
+ BF * Math.log(24, Math.sqrt(@fly)) / 60
93
+ else
94
+ BF / 60
95
+ end
96
+
97
+ @unit_text = unit.nil? ? '' : unit.to_s
98
+ @unit = unit
99
+
100
+ configure_barb_label
101
+ end
102
+
103
+ def configure_barb_label
104
+ barb_label = Rational(@config[:main_point_barb]) * @fly / BF
105
+ @barb_label = if barb_label == barb_label.to_i
106
+ "#{barb_label.to_i}#{@unit_text}"
107
+ else
108
+ "#{USPSFlags::Rational.new(barb_label).to_simplified_s}#{@unit_text}"
109
+ end
110
+ end
111
+
112
+ def spec_header
113
+ USPSFlags::Core::TridentSpecs::Header.new(
114
+ fly: @fly, fly_fraction: @fly_fraction, hoist: @hoist, hoist_fraction: @hoist_fraction,
115
+ unit_text: @unit_text, scaled_border: @scaled_border
116
+ ).p
117
+ end
118
+
119
+ def add_trident(type, box_top, box_bottom, box_left, box_right)
120
+ sym = { Short: :s, Delta: :d, Circle: :stf, Long: :n }[type]
121
+
122
+ Object.const_get("USPSFlags::Core::TridentSpecs::#{type}").new(
123
+ bt: box_top, bb: box_bottom, bl: box_left, br: box_right,
124
+ fly: @fly, unit: @unit, heading: heading(sym), config: @config
125
+ ).p
126
+ end
127
+
128
+ def heading(type_sym)
129
+ type, description = {
130
+ s: ['Short', 'Squadron Officers'], d: ['Delta', 'District Officers'],
131
+ stf: ['Circle', 'Staff Commanders Only'], n: ['Long', 'National Officers']
132
+ }[type_sym]
133
+
134
+ <<~SVG
135
+ <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>
136
+ <text x="#{BF / 2}" y="#{BH * 5 / 80}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#BF0D3E" text-anchor="middle">#{description}</text>
137
+ SVG
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -18,12 +18,12 @@ class USPSFlags
18
18
  <!-- Bottom -->
19
19
  #{bottom_bar_width} <!-- Bar width -->
20
20
  #{bottom_hash_width} <!-- Hash width -->
21
- #{Base::SA.horizontal(@box_bottom + @config[:bar_width] * 4, @box_left, @box_right, pointer_left: @box_bottom, pointer_right: @box_bottom, fly: @fly, unit: @unit)} <!-- Boundary width -->
21
+ #{SA.horizontal(@box_bottom + @config[:bar_width] * 4, @box_left, @box_right, pointer_left: @box_bottom, pointer_right: @box_bottom, fly: @fly, unit: @unit)} <!-- Boundary width -->
22
22
  SVG
23
23
  end
24
24
 
25
25
  def bottom_bar_width
26
- Base::SA.horizontal(
26
+ SA.horizontal(
27
27
  @box_bottom + @config[:bar_width], @config[:center_point] - @config[:bar_width] / 2,
28
28
  @config[:center_point] + @config[:bar_width] / 2,
29
29
  pointer_left: @box_bottom, pointer_right: @box_bottom, fly: @fly, unit: @unit
@@ -31,7 +31,7 @@ class USPSFlags
31
31
  end
32
32
 
33
33
  def bottom_hash_width
34
- Base::SA.horizontal(
34
+ SA.horizontal(
35
35
  @box_bottom + @config[:bar_width] * 2.5, @config[:center_point] - @config[:hash_width] / 2,
36
36
  @config[:center_point] + @config[:hash_width] / 2,
37
37
  pointer_left: bottom_hash_width_pointer_left, pointer_right: bottom_hash_width_pointer_right,
@@ -56,18 +56,18 @@ class USPSFlags
56
56
  end
57
57
 
58
58
  def top_side_point_width
59
- Base::SA.horizontal(
59
+ SA.horizontal(
60
60
  @box_top - @config[:bar_width], @box_left, @box_left + @config[:bar_width] * 3 / 2,
61
61
  pointer_left: @box_top, pointer_right: @box_top + @config[:bar_width] * 4 / 5 + @config[:side_point_height],
62
- label_offset: -Base::BF / 60, fly: @fly, unit: @unit
62
+ label_offset: -BF / 60, fly: @fly, unit: @unit
63
63
  )
64
64
  end
65
65
 
66
66
  def top_main_point_width
67
- Base::SA.horizontal(
67
+ SA.horizontal(
68
68
  @box_top - @config[:bar_width] * 2.5, top_main_point_top, @config[:center_point] + @config[:bar_width],
69
69
  pointer_left: @box_top + @config[:center_point_height], fly: @fly, unit: @unit,
70
- pointer_right: @box_top + @config[:center_point_height], label_offset: -Base::BF / 60
70
+ pointer_right: @box_top + @config[:center_point_height], label_offset: -BF / 60
71
71
  )
72
72
  end
73
73
 
@@ -18,7 +18,7 @@ class USPSFlags
18
18
  <!-- Overlay -->
19
19
  <!-- Main point barb -->
20
20
  #{overlay_lines}
21
- <text x="#{@config[:center_point] + @config[:bar_width] * 9 / 8}" y="#{@box_top + @config[:center_point_height] - @config[:main_point_barb]}" font-family="sans-serif" font-size="#{Base::BF / 100}px" fill="#041E42" text-anchor="left">#{@barb_label}</text>
21
+ <text x="#{@config[:center_point] + @config[:bar_width] * 9 / 8}" y="#{@box_top + @config[:center_point_height] - @config[:main_point_barb]}" font-family="sans-serif" font-size="#{BF / 100}px" fill="#041E42" text-anchor="left">#{@barb_label}</text>
22
22
  SVG
23
23
  end
24
24
 
@@ -16,7 +16,7 @@ class USPSFlags
16
16
  def right
17
17
  <<~SVG
18
18
  <!-- Right -->
19
- #{Base::SA.vertical(@box_right + @config[:bar_width], @box_top, @box_top + @config[:bar_width] * 4 / 5, pointer_top: @box_right, pointer_bottom: @box_right, fly: @fly, unit: @unit)} <!-- Side spike top gap -->
19
+ #{SA.vertical(@box_right + @config[:bar_width], @box_top, @box_top + @config[:bar_width] * 4 / 5, pointer_top: @box_right, pointer_bottom: @box_right, fly: @fly, unit: @unit)} <!-- Side spike top gap -->
20
20
  #{right_top_gap_to_hash_gap} <!-- Top gap to hash gap -->
21
21
  #{right_crossbar_to_hash_gap} <!-- Crossbar to hash gap -->
22
22
 
@@ -26,7 +26,7 @@ class USPSFlags
26
26
  end
27
27
 
28
28
  def right_top_gap_to_hash_gap
29
- Base::SA.vertical(
29
+ SA.vertical(
30
30
  @box_right + @config[:bar_width], @box_top + @config[:bar_width] * 4 / 5, right_top_gap_bottom,
31
31
  pointer_bottom: @box_right, fly: @fly, unit: @unit
32
32
  )
@@ -37,7 +37,7 @@ class USPSFlags
37
37
  end
38
38
 
39
39
  def right_crossbar_to_hash_gap
40
- Base::SA.vertical(
40
+ SA.vertical(
41
41
  @box_right + @config[:bar_width], right_crossbar_top, right_crossbar_bottom,
42
42
  pointer_bottom: @config[:center_point] + @config[:hash_width] / 2, fly: @fly, unit: @unit
43
43
  )
@@ -52,7 +52,7 @@ class USPSFlags
52
52
  end
53
53
 
54
54
  def right_hash
55
- Base::SA.vertical(
55
+ SA.vertical(
56
56
  @box_right + @config[:bar_width], right_hash_top, right_hash_bottom,
57
57
  pointer_bottom: @config[:center_point] + @config[:hash_width] / 2, fly: @fly, unit: @unit
58
58
  )
@@ -67,7 +67,7 @@ class USPSFlags
67
67
  end
68
68
 
69
69
  def right_hash_to_bottom
70
- Base::SA.vertical(
70
+ SA.vertical(
71
71
  @box_right + @config[:bar_width],
72
72
  @box_top + @config[:bar_width] * 38 / 10 + @config[:side_point_height] + @config[:side_spike_height],
73
73
  @box_bottom, pointer_bottom: @box_right, fly: @fly, unit: @unit
@@ -77,24 +77,24 @@ class USPSFlags
77
77
  def left
78
78
  <<~SVG
79
79
  <!-- Left -->
80
- #{Base::SA.vertical(@box_left - @config[:bar_width] * 5.25, @box_top, @box_bottom, pointer_top: @box_left, pointer_bottom: @box_left, fly: @fly, unit: @unit)} <!-- Boundary height -->
80
+ #{SA.vertical(@box_left - @config[:bar_width] * 5.25, @box_top, @box_bottom, pointer_top: @box_left, pointer_bottom: @box_left, fly: @fly, unit: @unit)} <!-- Boundary height -->
81
81
  #{left_main_point_height} <!-- Main point height -->
82
82
  #{left_side_point_height} <!-- Side point height -->
83
83
  SVG
84
84
  end
85
85
 
86
86
  def left_main_point_height
87
- Base::SA.vertical(
87
+ SA.vertical(
88
88
  @box_left - @config[:bar_width] * 0.75, @box_top, @box_top + @config[:center_point_height],
89
- pointer_bottom: @config[:center_point] - @config[:bar_width], label_offset: -Base::BF / 24,
90
- label_offset_y: -Base::BF / 60, label_align: 'middle', fly: @fly, unit: @unit
89
+ pointer_bottom: @config[:center_point] - @config[:bar_width], label_offset: -BF / 24,
90
+ label_offset_y: -BF / 60, label_align: 'middle', fly: @fly, unit: @unit
91
91
  )
92
92
  end
93
93
 
94
94
  def left_side_point_height
95
- Base::SA.vertical(
95
+ SA.vertical(
96
96
  @box_left - @config[:bar_width] * 1.5, @box_top + @config[:bar_width] * 4 / 5, left_side_point_bottom,
97
- pointer_top: @box_left, pointer_bottom: @box_left + @config[:bar_width], label_offset: -Base::BF / 24,
97
+ pointer_top: @box_left, pointer_bottom: @box_left + @config[:bar_width], label_offset: -BF / 24,
98
98
  label_align: 'middle', fly: @fly, unit: @unit
99
99
  )
100
100
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'usps_flags'
5
- s.version = '0.5.1'
6
- s.date = '2019-06-07'
5
+ s.version = '0.5.2'
6
+ s.date = '2019-06-14'
7
7
  s.summary = 'Flag generator for United States Power Squadrons'
8
8
  s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
9
9
  s.homepage = 'http://rubygems.org/gems/usps_flags'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-07 00:00:00.000000000 Z
11
+ date: 2019-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: file_utils
@@ -187,8 +187,10 @@ files:
187
187
  - LICENSE
188
188
  - README.md
189
189
  - Rakefile
190
+ - lib/modules.yml
190
191
  - lib/usps_flags.rb
191
192
  - lib/usps_flags/config.rb
193
+ - lib/usps_flags/configuration.rb
192
194
  - lib/usps_flags/core.rb
193
195
  - lib/usps_flags/core/ensign.rb
194
196
  - lib/usps_flags/core/field.rb
@@ -203,9 +205,9 @@ files:
203
205
  - lib/usps_flags/core/icons/trident_parts/hashes.rb
204
206
  - lib/usps_flags/core/icons/trumpet.rb
205
207
  - lib/usps_flags/core/pennant.rb
206
- - lib/usps_flags/core/trident_spec.rb
207
208
  - lib/usps_flags/core/trident_specs.rb
208
209
  - lib/usps_flags/core/trident_specs/base.rb
210
+ - lib/usps_flags/core/trident_specs/build.rb
209
211
  - lib/usps_flags/core/trident_specs/circle.rb
210
212
  - lib/usps_flags/core/trident_specs/delta.rb
211
213
  - lib/usps_flags/core/trident_specs/header.rb
@@ -1,144 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- # Core SVG data for the trident specification sheet.
4
- #
5
- # This class should never need to be called directly.
6
- # @private
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
142
- end
143
- end
144
- end