usps_flags 0.2.5 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69ddfedecc949a1b73696d9e704401373c004498
4
- data.tar.gz: ae233de37b620954b7ece25943544ae9e8c785a4
3
+ metadata.gz: 230cbb0c6890872f99ec67e5a5db72eb528b84bc
4
+ data.tar.gz: 54251932a8c574ebfa8efea790086eeec8cc5459
5
5
  SHA512:
6
- metadata.gz: 214c65edea1ecadeb32aa1b9e6b714fe7308622abf11e7804bd0ee58247b6b27f9ad30fcedb9cb0ac366bdcb7e8e96ec4003a3f658e119ee8bf05a5df86d4571
7
- data.tar.gz: f0cf6c15d23e78c768c968cd09a80bfd7bcaad4b30898c3b11666f82523adaafe717d04cc76474acdbd97da598def4385f848ccbb54b2118fdefa6e132d0801b
6
+ metadata.gz: 57d576e35c377d8527988d9fd51628712d6a3eaf8db4c9c137f4e657e61fb174f11c1868d407ab2dffce080ccdde5631e586e1f71e6b0fc610984ee8cf42ebaa
7
+ data.tar.gz: 80160eaa9c095e3a3af76d0c27550183b081c9599140c43b0a8c378e99359d96f65c1f6c32554238cbdd60e09908d5c57fe5635c81a0da6938c752fc0c54ff3d
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1,3 @@
1
- ��
2
- �L��0~1�lM��H�M�� Vw=�'��Q��$�7��[ �$���U�U�V*g���(;.ƥ�Eԡrm��F�"7�/}��j!H����Ir�g����f!��y���s��E$r �G��'�8b��/4�S�{�I ��|��F�GC���%�IՑ��Z$z!V�"@� c��UK��G3�E�waSgS��c��Iy�C��F��(�Ƈ��$Է�9B���\
1
+ j�7x��9Qb�?>q�����ڜ/4�����.��'n�
2
+ g
3
+ ��e+Dc�챢���
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/usps_flags.svg)](https://rubygems.org/gems/usps_flags)
4
4
  [![Build Status](https://travis-ci.org/jfiander/usps-flags.svg)](https://travis-ci.org/jfiander/usps-flags)
5
- [![Coverage Status](https://coveralls.io/repos/github/jfiander/usps-flags/badge.svg?branch=master&service=github)](https://coveralls.io/github/jfiander/usps-flags?branch=master)
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
 
8
8
  This gem allows you to generate precise SVG and PNG flag images based on
@@ -26,16 +26,6 @@ USPSFlags::Config.new do |config|
26
26
  end
27
27
  ```
28
28
 
29
- ### Other
30
-
31
- Run the following commands:
32
-
33
- ```ruby
34
- gem install usps_flags
35
- require 'usps_flags'
36
- USPSFlags::Config.flags_dir "path/to/flags/dir"
37
- ```
38
-
39
29
  ## Available flags
40
30
 
41
31
  - US Ensign
@@ -134,8 +124,6 @@ flag.svg #=> Generates SVG file at "/path/to/svg/output.svg"
134
124
  flag.png #=> Generates PNG file at "/path/to/png/output.png"
135
125
  ```
136
126
 
137
- - Calling any DSL method without argument, or with `nil` as argument will return
138
- the current value.
139
127
  - You can explicitly set `svg_file` to `""` to suppress printing the SVG content
140
128
  to console/log.
141
129
  - Calling `.png` requires `png_file` to be set.
@@ -89,8 +89,7 @@ class USPSFlags::Core::TridentSpec
89
89
  <<~SVG
90
90
  <!-- Short Trident -->
91
91
  <g transform="translate(-#{USPSFlags::Config::BASE_FLY*14/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
92
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Short</text>
93
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*5/80}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/40}px" fill="#BF0D3E" text-anchor="middle">Squadron Officers</text>
92
+ #{trident_heading(:s)}
94
93
 
95
94
  #{USPSFlags::Core::Trident.new(:s).svg}
96
95
 
@@ -132,8 +131,7 @@ class USPSFlags::Core::TridentSpec
132
131
  <<~SVG
133
132
  <!-- Delta Trident -->
134
133
  <g transform="translate(#{USPSFlags::Config::BASE_FLY*5/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
135
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Delta</text>
136
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*5/80}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/40}px" fill="#BF0D3E" text-anchor="middle">District Officers</text>
134
+ #{trident_heading(:d)}
137
135
 
138
136
  #{USPSFlags::Core::Trident.new(:d).svg}
139
137
 
@@ -155,21 +153,18 @@ class USPSFlags::Core::TridentSpec
155
153
  <<~SVG
156
154
  <!-- Circle Trident -->
157
155
  <g transform="translate(#{USPSFlags::Config::BASE_FLY*23/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
158
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Circle</text>
159
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*5/80}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/40}px" fill="#BF0D3E" text-anchor="middle">Staff Commanders Only</text>
156
+ #{trident_heading(:stf)}
160
157
 
161
158
  #{USPSFlags::Core::Trident.new(:stf).svg}
162
159
 
163
- <!-- Boundary box -->
164
- <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
160
+ #{long_trident_boundary_box(box_top, box_left, box_right)}
165
161
 
166
162
  <!-- Right -->
167
163
  #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*2, box_top+@trident_config[:crossbar_from_top]+@trident_config[:width], @trident_config[:center_point], @trident_config[:center_point], fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Inner circle diameter -->
168
164
  #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]+@trident_config[:width], nil, @trident_config[:center_point]+@trident_config[:bar_width]/2, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Outer circle diameter -->
169
165
  #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]+@trident_config[:width], box_bottom, nil, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Circle to bottom -->
170
166
 
171
- <!-- Left -->
172
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
167
+ #{long_trident_left_arrow(box_top, box_bottom, box_left, box_right)}
173
168
  </g></g>
174
169
  SVG
175
170
  end
@@ -178,20 +173,48 @@ class USPSFlags::Core::TridentSpec
178
173
  <<~SVG
179
174
  <!-- Long Trident -->
180
175
  <g transform="translate(#{USPSFlags::Config::BASE_FLY*40/80},#{USPSFlags::Config::BASE_HOIST*9/32})"><g transform="scale(0.7)">
181
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">Long</text>
182
- <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*5/80}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/40}px" fill="#BF0D3E" text-anchor="middle">National Officers</text>
176
+ #{trident_heading(:n)}
183
177
 
184
178
  #{USPSFlags::Core::Trident.new(:n).svg}
185
179
 
186
- <!-- Boundary box -->
187
- <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
180
+ #{long_trident_boundary_box(box_top, box_left, box_right)}
188
181
 
189
182
  <!-- Right -->
190
183
  #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3, box_bottom, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_right, fly: @fly, unit: @unit, font_size: @label_font_size)} <!-- Hash to bottom -->
191
184
 
192
- <!-- Left -->
193
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
185
+ #{long_trident_left_arrow(box_top, box_bottom, box_left, box_right)}
194
186
  </g></g>
195
187
  SVG
196
188
  end
189
+
190
+ def trident_heading(type_sym)
191
+ type, description = case type_sym
192
+ when :s
193
+ ["Short", "Squadron Officers"]
194
+ when :d
195
+ ["Delta", "District Officers"]
196
+ when :stf
197
+ ["Circle", "Staff Commanders Only"]
198
+ when :n
199
+ ["Long", "National Officers"]
200
+ end
201
+ <<~SVG
202
+ <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*1/40}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/30}px" font-weight="bold" fill="#BF0D3E" text-anchor="middle">#{type}</text>
203
+ <text x="#{USPSFlags::Config::BASE_FLY/2}" y="#{USPSFlags::Config::BASE_HOIST*5/80}" font-family="sans-serif" font-size="#{USPSFlags::Config::BASE_HOIST/40}px" fill="#BF0D3E" text-anchor="middle">#{description}</text>
204
+ SVG
205
+ end
206
+
207
+ def long_trident_boundary_box(box_top, box_left, box_right)
208
+ <<~SVG
209
+ <!-- Boundary box -->
210
+ <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*3/4}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
211
+ SVG
212
+ end
213
+
214
+ def long_trident_left_arrow(box_top, box_bottom, box_left, box_right)
215
+ <<~SVG
216
+ <!-- Left -->
217
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, font_size: @label_font_size, label_align: "middle")} <!-- Boundary height -->
218
+ SVG
219
+ end
197
220
  end
@@ -79,26 +79,16 @@ class USPSFlags::Generate
79
79
  # @param [Boolean] svg Generate zip archive of SVG images.
80
80
  # @param [Boolean] png Generate zip archive of PNG images.
81
81
  def zips(svg: true, png: true)
82
- ["svg", "png"].each do |format|
83
- begin
84
- if binding.local_variable_get(format)
85
- zip = "#{USPSFlags::Config.flags_dir}/ZIP/USPS_Flags.#{format}.zip"
86
- ::File.delete(zip) if ::File.exist?(zip)
87
- Zip::File.open(zip, Zip::File::CREATE) do |z|
88
- Dir.glob("#{USPSFlags::Config.flags_dir}/#{format.upcase}/**/*").each do |f|
89
- if f.split("/").last(2).first == "insignia"
90
- filename = "insignia/#{f.split("/").last}"
91
- z.add(filename, f)
92
- else
93
- z.add(f.split("/").last, f)
94
- end
95
- end
96
- end
97
- puts "Generated #{format.upcase} Zip"
98
- end
99
- rescue Errno::EACCES => e
100
- puts "Error: Failed to generate #{format.upcase} Zip -> #{e.message}"
101
- end
82
+ begin
83
+ generate_zip("svg") if svg
84
+ rescue Errno::EACCES => e
85
+ puts "Error: Failed to generate SVG Zip -> #{e.message}"
86
+ end
87
+
88
+ begin
89
+ generate_zip("png") if png
90
+ rescue Errno::EACCES => e
91
+ puts "Error: Failed to generate SVG Zip -> #{e.message}"
102
92
  end
103
93
  end
104
94
 
@@ -134,6 +124,26 @@ class USPSFlags::Generate
134
124
  [@svg_file, @png_file, @svg_ins_file, @png_ins_file]
135
125
  end
136
126
 
127
+ def generate_zip(type)
128
+ raise "Error: Flags directory not found." unless ::Dir.exist?("#{USPSFlags::Config.flags_dir}/ZIP")
129
+
130
+ zip = "#{USPSFlags::Config.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
131
+ ::File.delete(zip) if ::File.exist?(zip)
132
+
133
+ ::Zip::File.open(zip, Zip::File::CREATE) do |z|
134
+ ::Dir.glob("#{USPSFlags::Config.flags_dir}/#{type.upcase}/**/*").each do |f|
135
+ add_to_zip(z, f)
136
+ end
137
+ end
138
+ puts "Generated #{type.upcase} Zip"
139
+ end
140
+
141
+ def add_to_zip(z, f)
142
+ filename = f.split("/").last
143
+ filename = "insignia/#{filename}" if f.split("/").last(2).first == "insignia"
144
+ z.add(filename, f)
145
+ end
146
+
137
147
  def generate_static_images_for(flag, svg: true, png: true)
138
148
  start_time = Time.now
139
149
  # USPSFlags::Helpers.log " | | _ _ _ _ _ | \r".rjust(USPSFlags::Helpers.max_flag_name_length+31, " ")
@@ -159,55 +169,66 @@ class USPSFlags::Generate
159
169
  end
160
170
 
161
171
  def generate_static_svg(flag)
162
- begin
163
- USPSFlags::Helpers.log " "
164
- svg flag, outfile: @svg_file, scale: 1
165
- USPSFlags::Helpers.log "S"
166
- if USPSFlags::Helpers.valid_flags(:past).include?(flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
167
- USPSFlags::Helpers.log "-"
168
- else
169
- svg flag, field: false, outfile: @svg_ins_file, scale: 1
170
- USPSFlags::Helpers.log "I"
171
- end
172
- rescue => e
173
- USPSFlags::Helpers.log "x -> #{e.message}"
172
+ USPSFlags::Helpers.log " "
173
+ svg flag, outfile: @svg_file, scale: 1
174
+ USPSFlags::Helpers.log "S"
175
+ if USPSFlags::Helpers.valid_flags(:past).include?(flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
176
+ USPSFlags::Helpers.log "-"
177
+ else
178
+ svg flag, field: false, outfile: @svg_ins_file, scale: 1
179
+ USPSFlags::Helpers.log "I"
174
180
  end
181
+ rescue => e
182
+ USPSFlags::Helpers.log "x -> #{e.message}"
175
183
  end
176
184
 
177
185
  def generate_static_png(flag)
178
186
  USPSFlags::Helpers.log " | "
179
- begin
180
- USPSFlags::Helpers.log "…\b"
181
- png(File.read(@svg_file), outfile: @png_file) unless ::File.exist?(@png_file)
182
- USPSFlags::Helpers.log "F"
183
- if USPSFlags::Helpers.valid_flags(:past).include?(flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
184
- USPSFlags::Helpers.log "-"
185
- else
186
- USPSFlags::Helpers.log "…\b"
187
- png(File.read(@svg_ins_file), outfile: @png_ins_file, trim: true) unless ::File.exist?(@png_ins_file)
188
- USPSFlags::Helpers.log "I"
189
- end
190
- USPSFlags::Helpers.png_sizes.keys.each do |size|
191
- USPSFlags::Helpers.log(".") and next if ::File.exist?("#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size}.png")
192
-
193
- USPSFlags::Helpers.log "…\b"
194
- size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: flag)
195
- USPSFlags::Helpers.resize_png(@png_ins_file, flag: flag, size: size, size_key: size_key) if USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
196
- USPSFlags::Helpers.log USPSFlags::Helpers.png_sizes[size_key]
197
- if ::File.exist?(@png_ins_file) && ::File.exist?("#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size}.png")
198
- USPSFlags::Helpers.log "."
199
- elsif ::File.exist?(@png_ins_file) && MiniMagick::Image.open(@png_ins_file)[:width] > size && USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
200
- USPSFlags::Helpers.log "…\b"
201
- USPSFlags::Helpers.resize_png(@png_ins_file, flag: flag, size: size, size_key: size_key)
202
- USPSFlags::Helpers.log "i"
203
- elsif ::File.exist?(@png_ins_file)
204
- USPSFlags::Helpers.log "+"
205
- else
206
- USPSFlags::Helpers.log "-"
207
- end
208
- end
209
- rescue => e
210
- USPSFlags::Helpers.log "x -> #{e.message}"
187
+ generate_fullsize_png
188
+ generate_fullsize_png_insignia(flag)
189
+ generate_reduced_size_pngs
190
+ rescue => e
191
+ USPSFlags::Helpers.log "x -> #{e.message}"
192
+ end
193
+
194
+ def generate_fullsize_png
195
+ png(File.read(@svg_file), outfile: @png_file) unless ::File.exist?(@png_file)
196
+ USPSFlags::Helpers.log "F"
197
+ end
198
+
199
+ def generate_fullsize_png_insignia(flag)
200
+ if USPSFlags::Helpers.valid_flags(:past).include?(flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
201
+ USPSFlags::Helpers.log "-"
202
+ else
203
+ png(File.read(@svg_ins_file), outfile: @png_ins_file, trim: true) unless ::File.exist?(@png_ins_file)
204
+ USPSFlags::Helpers.log "I"
205
+ end
206
+ end
207
+
208
+ def generate_reduced_size_pngs
209
+ USPSFlags::Helpers.png_sizes.keys.each do |size|
210
+ USPSFlags::Helpers.log(".") and next if ::File.exist?("#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size}.png")
211
+ size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: flag)
212
+ generate_smaller_png(flag, size, size_key)
213
+ generate_smaller_png_insignia(flag, size, size_key)
214
+ end
215
+ end
216
+
217
+ def generate_smaller_png(flag, size, size_key)
218
+ USPSFlags::Helpers.resize_png(@png_ins_file, flag: flag, size: size, size_key: size_key) if USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
219
+ USPSFlags::Helpers.log USPSFlags::Helpers.png_sizes[size_key]
220
+ end
221
+
222
+ def generate_smaller_png_insignia(flag, size, size_key)
223
+ if ::File.exist?(@png_ins_file) && ::File.exist?("#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size}.png")
224
+ USPSFlags::Helpers.log "."
225
+ elsif ::File.exist?(@png_ins_file) && MiniMagick::Image.open(@png_ins_file)[:width] > size && USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
226
+ USPSFlags::Helpers.resize_png(@png_ins_file, flag: flag, size: size, size_key: size_key)
227
+ USPSFlags::Helpers.log "i"
228
+ elsif ::File.exist?(@png_ins_file)
229
+ USPSFlags::Helpers.log "+"
230
+ else
231
+ USPSFlags::Helpers.log "-"
211
232
  end
212
233
  end
213
234
  end
@@ -9,26 +9,11 @@ class USPSFlags::Helpers::SpecArrows
9
9
  # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
10
10
  # @private
11
11
  def vertical(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)
12
- label = bottom - top if label.nil?
13
- label = label.to_i if label - label.to_i == 0
14
- label = Rational(label) * fly / USPSFlags::Config::BASE_FLY
15
- if label == label.to_i
16
- label = label.to_i
17
- label_fraction = ""
18
- else
19
- label, label_fraction = label.to_simplified_a
20
- end
12
+ label, label_fraction = get_labels(bottom, top, fly, label: label)
21
13
  svg = ""
22
- unless pointer_top.nil?
23
- svg << <<~SVG
24
- <line x1="#{x}" y1="#{top}" x2="#{pointer_top}" y2="#{top}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
25
- SVG
26
- end
27
- unless pointer_bottom.nil?
28
- svg << <<~SVG
29
- <line x1="#{x}" y1="#{bottom}" x2="#{pointer_bottom}" y2="#{bottom}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
30
- SVG
31
- end
14
+
15
+ svg << arrow_pointer(x, pointer_top, top, top, color, stroke_width, stroke_dash) unless pointer_top.nil?
16
+ svg << arrow_pointer(x, pointer_bottom, bottom, bottom, color, stroke_width, stroke_dash) unless pointer_bottom.nil?
32
17
 
33
18
  svg << <<~SVG
34
19
  <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" />
@@ -46,26 +31,11 @@ class USPSFlags::Helpers::SpecArrows
46
31
  # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
47
32
  # @private
48
33
  def horizontal(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)
49
- label = right - left if label.nil?
50
- label = label.to_i if label - label.to_i == 0
51
- label = Rational(label) * fly / USPSFlags::Config::BASE_FLY
52
- if label == label.to_i
53
- label = label.to_i
54
- label_fraction = ""
55
- else
56
- label, label_fraction = label.to_simplified_a
57
- end
34
+ label, label_fraction = get_labels(right, left, fly, label: label)
58
35
  svg = ""
59
- unless pointer_left.nil?
60
- svg << <<~SVG
61
- <line x1="#{left}" y1="#{y}" x2="#{left}" y2="#{pointer_left}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
62
- SVG
63
- end
64
- unless pointer_right.nil?
65
- svg << <<~SVG
66
- <line x1="#{right}" y1="#{y}" x2="#{right}" y2="#{pointer_right}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
67
- SVG
68
- end
36
+
37
+ svg << arrow_pointer(left, left, pointer_left, y, color, stroke_width, stroke_dash) unless pointer_left.nil?
38
+ svg << arrow_pointer(right, right, y, pointer_right, color, stroke_width, stroke_dash) unless pointer_right.nil?
69
39
 
70
40
  svg << <<~SVG
71
41
  <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" />
@@ -77,5 +47,25 @@ class USPSFlags::Helpers::SpecArrows
77
47
 
78
48
  svg
79
49
  end
50
+
51
+ private
52
+ def arrow_pointer(x1, x2, y1, y2, color, stroke_width, stroke_dash)
53
+ <<~SVG
54
+ <line x1="#{x1}" y1="#{y1}" x2="#{x2}" y2="#{y2}" stroke="#{color}" stroke-width="#{stroke_width}" stroke-dasharray="#{stroke_dash}" />
55
+ SVG
56
+ end
57
+
58
+ def get_labels(a, b, fly, label: nil)
59
+ label = a - b if label.nil?
60
+ label = label.to_i if label - label.to_i == 0
61
+ label = Rational(label) * fly / USPSFlags::Config::BASE_FLY
62
+ if label == label.to_i
63
+ label = label.to_i
64
+ label_fraction = ""
65
+ else
66
+ label, label_fraction = label.to_simplified_a
67
+ end
68
+ [label, label_fraction]
69
+ end
80
70
  end
81
71
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'usps_flags'
3
- s.version = '0.2.5'
4
- s.date = '2017-11-05'
3
+ s.version = '0.2.6'
4
+ s.date = '2017-11-06'
5
5
  s.summary = 'Flag generator for United States Power Squadrons'
6
6
  s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
7
7
  s.homepage = 'http://rubygems.org/gems/usps_flags'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -30,7 +30,7 @@ cert_chain:
30
30
  3YzYAc+kXfD7kkzA2NMvLT6Q1v03qQyIZ8BS8SNk5wLGAdLM+IravFDLEs448fjz
31
31
  lEAU0RHLFVbE+CXW6makIlWGHR0=
32
32
  -----END CERTIFICATE-----
33
- date: 2017-11-05 00:00:00.000000000 Z
33
+ date: 2017-11-06 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: file_utils
metadata.gz.sig CHANGED
Binary file