usps_flags 0.6.0 → 0.6.3

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: 834c5fd9b07cda04e1abbb43ce057be5bcb75a2338c4c9c9b30bf90e873c70a3
4
- data.tar.gz: 2c1967a3acab412d00a70d2b7b529494128daf71c99c9484f8fd5dc51edade5d
3
+ metadata.gz: f1fce1ce11314457a3e98a2ab0fcdb8027622afe1b1236403e966e903da0ff68
4
+ data.tar.gz: 31ca874c27dc4ea1874798a4bbd0071ec704915e9534470f6b5d3f318d9f3cfc
5
5
  SHA512:
6
- metadata.gz: 79d043fc636b58a3bc1181716b9a21fb2fe64b552b6e376035b096ea97682aa2d36bb24896ae711b86baef52779c457dadabf17b364cc23500cb1edb1d802145
7
- data.tar.gz: 3eef4c97b191637097e01444658635882cb1b4552c2705543b6c0c77e4c5923a211430d1026f9a202d6f637a101128df6224ef5f90e0be070d4b0efa64554ab4
6
+ metadata.gz: 95f901e036ee037531a550b074f111693958380e77e855b3f9e2d851a7407c96fec5fd77c9f9af0798d28edeece9adf2c21f3640eb635a512d9404a32d8cb0ec
7
+ data.tar.gz: 12cd8344933826262a3bbac4fa3e8d648d04d668d0d4d39937ff15e99645eed83516809e613838708b20f80120f1a3126cf93c9212c0af8772f838a65f8e97cb
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.4
data/CC.png ADDED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.6.0)
4
+ usps_flags (0.6.3)
5
5
  file_utils (~> 1.1, >= 1.1.2)
6
6
  mini_magick (~> 4.9, >= 4.9.4)
7
7
  rubyzip (~> 1.3, >= 1.3.0)
@@ -9,51 +9,57 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- ast (2.4.0)
13
- diff-lcs (1.3)
14
- docile (1.1.5)
12
+ ast (2.4.2)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
15
  file_utils (1.1.2)
16
- jaro_winkler (1.5.4)
17
- json (2.1.0)
18
- mini_magick (4.10.1)
19
- parallel (1.19.1)
20
- parser (2.6.5.0)
21
- ast (~> 2.4.0)
22
- rainbow (3.0.0)
23
- rake (12.3.0)
24
- rspec (3.7.0)
25
- rspec-core (~> 3.7.0)
26
- rspec-expectations (~> 3.7.0)
27
- rspec-mocks (~> 3.7.0)
28
- rspec-core (3.7.0)
29
- rspec-support (~> 3.7.0)
30
- rspec-expectations (3.7.0)
16
+ mini_magick (4.11.0)
17
+ parallel (1.21.0)
18
+ parser (3.1.1.0)
19
+ ast (~> 2.4.1)
20
+ rainbow (3.1.1)
21
+ rake (12.3.3)
22
+ regexp_parser (2.2.1)
23
+ rexml (3.2.5)
24
+ rspec (3.11.0)
25
+ rspec-core (~> 3.11.0)
26
+ rspec-expectations (~> 3.11.0)
27
+ rspec-mocks (~> 3.11.0)
28
+ rspec-core (3.11.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-expectations (3.11.0)
31
31
  diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.7.0)
33
- rspec-mocks (3.7.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-mocks (3.11.0)
34
34
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.7.0)
36
- rspec-support (3.7.0)
37
- rubocop (0.77.0)
38
- jaro_winkler (~> 1.5.1)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-support (3.11.0)
37
+ rubocop (0.93.1)
39
38
  parallel (~> 1.10)
40
- parser (>= 2.6)
39
+ parser (>= 2.7.1.5)
41
40
  rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8)
42
+ rexml
43
+ rubocop-ast (>= 0.6.0)
42
44
  ruby-progressbar (~> 1.7)
43
- unicode-display_width (>= 1.4.0, < 1.7)
44
- rubocop-rspec (1.33.0)
45
- rubocop (>= 0.60.0)
46
- ruby-progressbar (1.10.1)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-ast (1.16.0)
47
+ parser (>= 3.1.1.0)
48
+ rubocop-rspec (1.44.1)
49
+ rubocop (~> 0.87)
50
+ rubocop-ast (>= 0.7.1)
51
+ ruby-progressbar (1.11.0)
47
52
  rubyzip (1.3.0)
48
- simplecov (0.15.1)
49
- docile (~> 1.1.0)
50
- json (>= 1.8, < 3)
51
- simplecov-html (~> 0.10.0)
52
- simplecov-html (0.10.2)
53
- unicode-display_width (1.6.0)
53
+ simplecov (0.21.2)
54
+ docile (~> 1.1)
55
+ simplecov-html (~> 0.11)
56
+ simplecov_json_formatter (~> 0.1)
57
+ simplecov-html (0.12.3)
58
+ simplecov_json_formatter (0.1.4)
59
+ unicode-display_width (1.8.0)
54
60
 
55
61
  PLATFORMS
56
- ruby
62
+ arm64-darwin-21
57
63
 
58
64
  DEPENDENCIES
59
65
  rake (~> 12.2, >= 12.2.1)
@@ -64,4 +70,4 @@ DEPENDENCIES
64
70
  usps_flags!
65
71
 
66
72
  BUNDLED WITH
67
- 1.17.3
73
+ 2.2.31
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # United States Power Squadrons® Flag Generator
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/usps_flags.svg)](https://rubygems.org/gems/usps_flags)
4
- [![Build Status](https://travis-ci.org/jfiander/usps-flags.svg)](https://travis-ci.org/jfiander/usps-flags)
4
+ [![Build Status](https://img.shields.io/travis/jfiander/usps-flags/master.svg)](https://travis-ci.org/jfiander/usps-flags)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/760b824f0edac3316a11/test_coverage)](https://codeclimate.com/github/jfiander/usps-flags/test_coverage)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/760b824f0edac3316a11/maintainability)](https://codeclimate.com/github/jfiander/usps-flags/maintainability)
7
7
 
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: false
2
+
3
+ # Core SVG data for the trident intersections 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 BuildIntersections
11
+ def initialize(fly: 2048, scaled_border: false)
12
+ @scaled_border = scaled_border
13
+ configure_sizes(fly)
14
+ configure_labels('')
15
+ end
16
+
17
+ def svg
18
+ svg = spec_header
19
+ svg << add_cc_intersection
20
+ svg << add_vc_intersection
21
+ svg
22
+ end
23
+
24
+ private
25
+
26
+ def add_cc_intersection
27
+ svg = +''
28
+
29
+ svg += "<g transform=\"translate(-#{BF * 1 / 16}, #{BH / 4}) scale(0.6)\">"
30
+ svg += USPSFlags::Core::Tridents.cc(trident_color: :blue)
31
+ svg += label('CC', Rational(1, 3))
32
+ svg += '</g>'
33
+
34
+ svg
35
+ end
36
+
37
+ def add_vc_intersection
38
+ svg = +''
39
+
40
+ svg += "<g transform=\"translate(#{BF * 7 / 16}, #{BH / 4}) scale(0.6)\">"
41
+ svg += USPSFlags::Core::Tridents.vc(trident_color: :red)
42
+ svg += label('VC', Rational(15, 32))
43
+ svg += '</g>'
44
+
45
+ svg
46
+ end
47
+
48
+ def label_offset
49
+ BF.to_f * 1 / 32
50
+ end
51
+
52
+ def label_height
53
+ BF.to_f * 15 / 64
54
+ end
55
+
56
+ def label(type, fraction)
57
+ <<~SVG
58
+ <!-- #{type} Intersection -->
59
+ <g transform="translate(#{BF / 2}, #{BH - 200}) rotate(45)">
60
+ #{big_arrow}
61
+ #{small_arrow(fraction)}
62
+ </g>
63
+ SVG
64
+ end
65
+
66
+ def small_arrow(fraction)
67
+ SA.vertical(
68
+ label_offset, -label_height * fraction, 0,
69
+ pointer_top: label_height * fraction, pointer_bottom: 0, label_offset: BF / 35,
70
+ label_offset_y: -BF / 50, label_align: 'middle', fly: @fly, unit: @unit
71
+ )
72
+ end
73
+
74
+ def big_arrow
75
+ SA.vertical(
76
+ label_offset * 3, -label_height, 0,
77
+ pointer_top: label_height, pointer_bottom: 0, label_offset: BF / 60,
78
+ label_offset_y: -BF / 10, label_align: 'left', fly: @fly, unit: @unit
79
+ )
80
+ end
81
+
82
+ def configure_sizes(fly)
83
+ @fly = Rational(fly)
84
+ get_hoist_from_fly(@fly)
85
+ configure_hoist_fraction
86
+ configure_fly_fraction
87
+ end
88
+
89
+ def get_hoist_from_fly(fly)
90
+ hoist = (fly * Rational(2, 3))
91
+ @hoist = hoist
92
+ end
93
+
94
+ def configure_hoist_fraction
95
+ @hoist, @hoist_fraction = USPSFlags::Rational.new(@hoist).to_simplified_a
96
+ end
97
+
98
+ def configure_fly_fraction
99
+ @fly, @fly_fraction = USPSFlags::Rational.new(@fly).to_simplified_a
100
+ end
101
+
102
+ def configure_labels(unit)
103
+ @label_font_size = BF / 60
104
+
105
+ @unit_text = unit.nil? ? '' : unit.to_s
106
+ @unit = unit
107
+ end
108
+
109
+ def spec_header
110
+ USPSFlags::Core::TridentSpecs::Header.new(
111
+ fly: @fly, fly_fraction: @fly_fraction, hoist: @hoist, hoist_fraction: @hoist_fraction,
112
+ unit_text: @unit_text, scaled_border: @scaled_border, no_measurements: true
113
+ ).p
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -15,6 +15,7 @@ class USPSFlags
15
15
  @hoist_fraction = options[:hoist_fraction]
16
16
  @unit_text = options[:unit_text]
17
17
  @scaled_border = options[:scaled_border]
18
+ @no_measurements = options.key?(:no_measurements) && options[:no_measurements]
18
19
  end
19
20
 
20
21
  def p
@@ -43,11 +44,21 @@ class USPSFlags
43
44
  <text x="#{BF / 2}" y="#{BH * 3 / 40}" font-family="sans-serif" font-size="#{BH / 20}px" font-weight="bold" fill="#041E42" text-anchor="middle">United States Power Squadrons<tspan class="heading" dy ="-#{BH / 50}">®</tspan></text>
44
45
  </g>
45
46
  <text x="#{BF / 2}" y="#{BH / 8}" font-family="sans-serif" font-size="#{BH / 30}px" fill="#041E42" text-anchor="middle">Officer Flag Trident Specification</text>
47
+ #{measurements_are_relative}
48
+ SVG
49
+ end
50
+
51
+ def measurements_are_relative
52
+ return if @no_measurements
53
+
54
+ <<~SVG
46
55
  <text x="#{BF / 2}" y="#{BH * 2 / 11}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#041E42" text-anchor="middle">All measurements are relative to a field with</text>
47
56
  SVG
48
57
  end
49
58
 
50
59
  def units
60
+ return angles if @no_measurements
61
+
51
62
  <<~SVG
52
63
  <g>
53
64
  <style><![CDATA[tspan.title{font-size: #{USPSFlags::Config::FRACTION_SCALE * 9 / 10}%;}]]></style>
@@ -58,6 +69,12 @@ class USPSFlags
58
69
  SVG
59
70
  end
60
71
 
72
+ def angles
73
+ <<~SVG
74
+ <text x="#{BF / 2}" y="#{BH * 4 / 19}" font-family="sans-serif" font-size="#{BH / 40}px" fill="#041E42" text-anchor="middle">Angled tridents are 45 degrees from vertical.</text>
75
+ SVG
76
+ end
77
+
61
78
  def scaled_border
62
79
  <<~SVG
63
80
  <!-- Flag border scaled to spec trident size -->
@@ -18,6 +18,7 @@ class USPSFlags
18
18
  require 'usps_flags/core/trident_specs/long'
19
19
  require 'usps_flags/core/trident_specs/circle'
20
20
  require 'usps_flags/core/trident_specs/build'
21
+ require 'usps_flags/core/trident_specs/build_intersections'
21
22
  end
22
23
  end
23
24
  end
@@ -10,38 +10,32 @@ class USPSFlags
10
10
  class << self
11
11
  # The side C/C tridents are angled 45 degrees, and intersect the central one at 1/3 up from the bottom
12
12
  #
13
- # Note: translate(132, 130) corrects the center of rotation for each angled trident due to the (transparent)
14
- # field size of the include trident SVG
15
- #
16
13
  # Center of rotation:
17
14
  # # radius = USPSFlags.configuration.trident[:bar_width] / 2
18
15
  # <circle cx="#{cc_center[:x]}" cy="#{cc_center[:y]}" r="#{radius}" fill="red" />
19
- def cc(type, trident_color:)
20
- trident = USPSFlags::Core.trident(type, color: trident_color)
16
+ def cc(_ = nil, trident_color:)
17
+ trident = USPSFlags::Core.trident(:n, color: trident_color)
18
+ x_distance = USPSFlags::Config::BASE_FLY * 4 / 39 # 4/39 or 28/39
19
+ y_distance = USPSFlags::Config::BASE_FLY * 2 / 39 # 5/78 or 27/156
21
20
  <<~SVG
22
- <g transform="translate(132, 130)">
23
- <g transform="rotate(-45, #{cc_center[:x]}, #{cc_center[:y]})">
24
- #{trident}
25
- </g>
26
- <g transform="rotate(45, #{cc_center[:x]}, #{cc_center[:y]})">
27
- #{trident}
28
- </g>
21
+ <g transform="translate(-#{x_distance * 1.25}, #{y_distance})">
22
+ <g transform="rotate(-45, #{USPSFlags::Config::BASE_FLY / 2}, #{USPSFlags::Config::BASE_HOIST / 2})">\n#{trident}</g>
23
+ </g>
24
+ \n#{trident}
25
+ <g transform="translate(#{x_distance * 1.25}, #{y_distance})">
26
+ <g transform="rotate(45)" transform-origin="center">\n#{trident}</g>
29
27
  </g>
30
- #{trident}
31
28
  SVG
32
29
  end
33
30
 
34
31
  # V/C tridents are angled 45 degrees, and intersect at 15/32 up from the bottom
35
- #
36
- # Note: translate(132, 50) corrects the center of rotation for each angled trident due to the (transparent)
37
- # field size of the include trident SVG
38
- def vc(type, trident_color:)
39
- trident = USPSFlags::Core.trident(type, color: trident_color)
32
+ def vc(_ = nil, trident_color:)
33
+ trident = USPSFlags::Core.trident(:n, color: trident_color)
40
34
  <<~SVG
41
- <g transform="translate(132, 50) rotate(-45, #{vc_center[:x]}, #{vc_center[:y]})">
35
+ <g transform="rotate(-45, #{vc_center[:x]}, #{vc_center[:y]})">
42
36
  #{trident}
43
37
  </g>
44
- <g transform="translate(132, 50) rotate(45, #{vc_center[:x]}, #{vc_center[:y]})">
38
+ <g transform="rotate(45, #{vc_center[:x]}, #{vc_center[:y]})">
45
39
  #{trident}
46
40
  </g>
47
41
  SVG
@@ -84,14 +78,10 @@ class USPSFlags
84
78
  def rotation_center(height_fraction)
85
79
  {
86
80
  x: USPSFlags::Config::BASE_FLY / 2,
87
- y: (USPSFlags::Config::BASE_HOIST * 7 / 8) - (n_staff_height * height_fraction)
81
+ y: (USPSFlags::Config::BASE_HOIST * 7 / 8) - (n_staff_height * height_fraction).to_f
88
82
  }
89
83
  end
90
84
 
91
- def cc_center
92
- rotation_center(Rational(1, 3))
93
- end
94
-
95
85
  def vc_center
96
86
  rotation_center(Rational(15, 32))
97
87
  end
@@ -10,6 +10,10 @@ class USPSFlags
10
10
  USPSFlags::Core::TridentSpecs::Build.new(fly: fly, unit: unit, scaled_border: scaled_border).svg
11
11
  end
12
12
 
13
+ def self.intersection_spec(fly: 2048, scaled_border: false)
14
+ USPSFlags::Core::TridentSpecs::BuildIntersections.new(fly: fly, scaled_border: scaled_border).svg
15
+ end
16
+
13
17
  def self.headers(width: nil, height: nil, pennant: false, scale: nil, title: 'USPS Flag')
14
18
  USPSFlags::Core::Headers.new(width: width, height: height, pennant: pennant, scale: scale, title: title).svg
15
19
  end
@@ -103,6 +103,22 @@ class USPSFlags
103
103
  USPSFlags::Helpers.output(svg, outfile: outfile)
104
104
  end
105
105
 
106
+ # Generate trident spec sheet for National Bridge intersections as an SVG image.
107
+ #
108
+ # @param [String] outfile The path to save the SVG file to. If not set, prints to console.
109
+ # @param [Integer] fly The nominal fly length of an appropriate flag field for the generated tridents.
110
+ # @param [String] outfile The unit to append to all trident measurements.
111
+ # @param [String] scale The image scale divisor factor.
112
+ # @return [String] Returns the SVG data.
113
+ def intersection_spec(outfile: nil, fly: 2048, scale: nil, scaled_border: false)
114
+ svg = +''
115
+ svg << USPSFlags::Core.headers(scale: scale, title: 'USPS Trident Specifications')
116
+ svg << USPSFlags::Core.intersection_spec(fly: fly, scaled_border: scaled_border)
117
+ svg << USPSFlags::Core.footer
118
+
119
+ USPSFlags::Helpers.output(svg, outfile: outfile)
120
+ end
121
+
106
122
  private
107
123
 
108
124
  def special_flag(flag, outfile, scale)
@@ -88,6 +88,10 @@ describe USPSFlags::Generate do
88
88
  it 'generates the trident specification sheet with a fractional field size' do
89
89
  expect(described_class.spec(outfile: '', fly: 23.5)).to include('<title>USPS Trident Specifications</title>')
90
90
  end
91
+
92
+ it 'generates the intersection specification sheet' do
93
+ expect(described_class.intersection_spec(outfile: '')).to include('CC Intersection')
94
+ end
91
95
  end
92
96
 
93
97
  describe 'png' do
data/usps_flags.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'usps_flags'
5
- s.version = '0.6.0'
6
- s.date = '2020-02-17'
5
+ s.version = '0.6.3'
6
+ s.date = '2022-03-10'
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.6.0
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2022-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: file_utils
@@ -179,8 +179,10 @@ files:
179
179
  - ".gitignore"
180
180
  - ".rspec"
181
181
  - ".rubocop.yml"
182
+ - ".ruby-version"
182
183
  - ".travis.yml"
183
184
  - ".yardopts"
185
+ - CC.png
184
186
  - CONTRIBUTING.md
185
187
  - Gemfile
186
188
  - Gemfile.lock
@@ -208,6 +210,7 @@ files:
208
210
  - lib/usps_flags/core/trident_specs.rb
209
211
  - lib/usps_flags/core/trident_specs/base.rb
210
212
  - lib/usps_flags/core/trident_specs/build.rb
213
+ - lib/usps_flags/core/trident_specs/build_intersections.rb
211
214
  - lib/usps_flags/core/trident_specs/circle.rb
212
215
  - lib/usps_flags/core/trident_specs/delta.rb
213
216
  - lib/usps_flags/core/trident_specs/header.rb
@@ -260,8 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
263
  - !ruby/object:Gem::Version
261
264
  version: '0'
262
265
  requirements: []
263
- rubyforge_project:
264
- rubygems_version: 2.7.6
266
+ rubygems_version: 3.1.6
265
267
  signing_key:
266
268
  specification_version: 4
267
269
  summary: Flag generator for United States Power Squadrons