usps_flags 0.3.5 → 0.3.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: 6f005b5e851564f4b8496aa3489b678a47c8cf9f
4
- data.tar.gz: a5f44daaac686d24673233b5f503fa3d3685eeb7
3
+ metadata.gz: 110a91c58d80cd70fd0afbf419ab79d11725cfb0
4
+ data.tar.gz: 7d1b828211cd366543c74afab5dd649cee0168ca
5
5
  SHA512:
6
- metadata.gz: 8e3831a3046a633600d8388727461f160704229690fe4ec57ae747933c60059e09bdf3b950d1cfd4dbe6548814e8848a5d6e1fe0430b678e09b9b44f67c5ef15
7
- data.tar.gz: 0f9387270b6fae9bc37a6a40961d75eb520f99e81dae1748f71dbeda3503d176a829c2efb14fc8a70350fad32568e5a7c9963af2774d27bcf6a8b254b69d9bbe
6
+ metadata.gz: bb1fc483ab32514e973fb070f57d538ccfbfb5a35ad6865d895563c1dfdf2bbf0825078ccc4f40c2ed577b3e18070f04a27d54f0bdca9009722a385b4882617f
7
+ data.tar.gz: '0283ab2c942b70f56848ad0fc78755b7196a6e964e297cdf28ba877e0ce0c76d67c1ce9b9fb5678dd0053e81c9022fb7283552ce493217de24d70b60f7eef41e'
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.3.4)
4
+ usps_flags (0.3.5)
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)
@@ -32,7 +32,7 @@ class USPSFlags::Core::TridentSpec
32
32
 
33
33
  private
34
34
  def configure_sizes(fly)
35
- @fly = fly
35
+ @fly = Rational(fly)
36
36
  get_hoist_from_fly(@fly)
37
37
  configure_hoist_fraction
38
38
  configure_fly_fraction
@@ -119,26 +119,26 @@ class USPSFlags::Core::TridentSpec
119
119
  <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST/2}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
120
120
 
121
121
  <!-- Right -->
122
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top, box_top+@trident_config[:bar_width], box_right, box_right)} <!-- Side spike top gap -->
123
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, box_right)} <!-- Top gap to hash gap -->
124
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2)} <!-- Crossbar to hash gap -->
122
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top, box_top+@trident_config[:bar_width], box_right, box_right, fly: @fly, unit: @unit)} <!-- Side spike top gap -->
123
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, box_right, fly: @fly, unit: @unit)} <!-- Top gap to hash gap -->
124
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*2+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2, fly: @fly, unit: @unit)} <!-- Crossbar to hash gap -->
125
125
 
126
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2)} <!-- Hash -->
127
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_bottom, nil, box_right)} <!-- Hash to bottom -->
126
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*3+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], nil, @trident_config[:center_point]+@trident_config[:hash_width]/2, fly: @fly, unit: @unit)} <!-- Hash -->
127
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_bottom, nil, box_right, fly: @fly, unit: @unit)} <!-- Hash to bottom -->
128
128
 
129
129
  <!-- Left -->
130
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*5.25, box_top, box_bottom, box_left, box_left)} <!-- Boundary height -->
131
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*0.75, box_top, box_top+@trident_config[:point_height], nil, @trident_config[:center_point]-@trident_config[:bar_width], label_offset: -USPSFlags::Config::BASE_FLY/26, label_offset_y: -USPSFlags::Config::BASE_FLY/100, label_align: "middle")} <!-- Main point height -->
132
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]+@trident_config[:point_height], box_left, box_left+@trident_config[:bar_width], label_offset: -USPSFlags::Config::BASE_FLY/24, label_align: "middle")} <!-- Side point height -->
130
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*5.25, box_top, box_bottom, box_left, box_left, fly: @fly, unit: @unit)} <!-- Boundary height -->
131
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*0.75, box_top, box_top+@trident_config[:point_height], nil, @trident_config[:center_point]-@trident_config[:bar_width], label_offset: -USPSFlags::Config::BASE_FLY/26, label_offset_y: -USPSFlags::Config::BASE_FLY/100, label_align: "middle", fly: @fly, unit: @unit)} <!-- Main point height -->
132
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top+@trident_config[:bar_width], box_top+@trident_config[:bar_width]+@trident_config[:point_height], box_left, box_left+@trident_config[:bar_width], label_offset: -USPSFlags::Config::BASE_FLY/24, label_align: "middle", fly: @fly, unit: @unit)} <!-- Side point height -->
133
133
 
134
134
  <!-- Bottom -->
135
- #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width], @trident_config[:center_point]-@trident_config[:bar_width]/2, @trident_config[:center_point]+@trident_config[:bar_width]/2, box_bottom, box_bottom)} <!-- Bar width -->
136
- #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:hash_width]/2, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height])} <!-- Hash width -->
137
- #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width]*4, box_left, box_right, box_bottom, box_bottom)} <!-- Boundary width -->
135
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width], @trident_config[:center_point]-@trident_config[:bar_width]/2, @trident_config[:center_point]+@trident_config[:bar_width]/2, box_bottom, box_bottom, fly: @fly, unit: @unit)} <!-- Bar width -->
136
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:hash_width]/2, @trident_config[:center_point]+@trident_config[:hash_width]/2, box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], box_top+@trident_config[:bar_width]*4+@trident_config[:point_height]+@trident_config[:side_spike_height], fly: @fly, unit: @unit)} <!-- Hash width -->
137
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_bottom+@trident_config[:bar_width]*4, box_left, box_right, box_bottom, box_bottom, fly: @fly, unit: @unit)} <!-- Boundary width -->
138
138
 
139
139
  <!-- Top -->
140
- #{USPSFlags::Helpers::SpecArrows.horizontal(box_top-@trident_config[:bar_width], box_left, box_left+@trident_config[:bar_width]*3/2, box_top, box_top+@trident_config[:bar_width]+@trident_config[:point_height], label_offset: -USPSFlags::Config::BASE_FLY/60)} <!-- Side point width -->
141
- #{USPSFlags::Helpers::SpecArrows.horizontal(box_top-@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:bar_width], @trident_config[:center_point]+@trident_config[:bar_width], box_top+@trident_config[:point_height], box_top+@trident_config[:point_height], label_offset: -USPSFlags::Config::BASE_FLY/60)} <!-- Main point width -->
140
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_top-@trident_config[:bar_width], box_left, box_left+@trident_config[:bar_width]*3/2, box_top, box_top+@trident_config[:bar_width]+@trident_config[:point_height], label_offset: -USPSFlags::Config::BASE_FLY/60, fly: @fly, unit: @unit)} <!-- Side point width -->
141
+ #{USPSFlags::Helpers::SpecArrows.horizontal(box_top-@trident_config[:bar_width]*2.5, @trident_config[:center_point]-@trident_config[:bar_width], @trident_config[:center_point]+@trident_config[:bar_width], box_top+@trident_config[:point_height], box_top+@trident_config[:point_height], label_offset: -USPSFlags::Config::BASE_FLY/60, fly: @fly, unit: @unit)} <!-- Main point width -->
142
142
 
143
143
  <!-- Overlay -->
144
144
  <!-- Main point barb -->
@@ -161,12 +161,12 @@ class USPSFlags::Core::TridentSpec
161
161
  <rect x="#{box_left}" y="#{box_top}" width="#{box_right-box_left}" height="#{USPSFlags::Config::BASE_HOIST*5/8}" stroke="#666666" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" stroke-dasharray="15, 15" fill="none" />
162
162
 
163
163
  <!-- Right -->
164
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width]-@trident_config[:delta_gap_height], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], @trident_config[:center_point], @trident_config[:center_point]+@trident_config[:delta_gap_width])} <!-- Delta gap height -->
165
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], nil, box_right)} <!-- Delta width -->
166
- #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], box_bottom, nil, box_right)} <!-- Delta to bottom -->
164
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width]-@trident_config[:delta_gap_height], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], @trident_config[:center_point], @trident_config[:center_point]+@trident_config[:delta_gap_width], fly: @fly, unit: @unit)} <!-- Delta gap height -->
165
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom]-@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], nil, box_right, fly: @fly, unit: @unit)} <!-- Delta width -->
166
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_right+@trident_config[:bar_width], box_bottom-@trident_config[:delta_from_bottom], box_bottom, nil, box_right, fly: @fly, unit: @unit)} <!-- Delta to bottom -->
167
167
 
168
168
  <!-- Left -->
169
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY*2/11, label_align: "middle")} <!-- Boundary height -->
169
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY*2/11, label_align: "middle", fly: @fly, unit: @unit)} <!-- Boundary height -->
170
170
  </g></g>
171
171
  SVG
172
172
  end
@@ -182,9 +182,9 @@ class USPSFlags::Core::TridentSpec
182
182
  #{long_trident_boundary_box(box_top, box_left, box_right)}
183
183
 
184
184
  <!-- Right -->
185
- #{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])} <!-- Inner circle diameter -->
186
- #{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)} <!-- Outer circle diameter -->
187
- #{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)} <!-- Circle to bottom -->
185
+ #{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)} <!-- Inner circle diameter -->
186
+ #{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)} <!-- Outer circle diameter -->
187
+ #{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)} <!-- Circle to bottom -->
188
188
 
189
189
  #{long_trident_left_arrow(box_top, box_bottom, box_left, box_right)}
190
190
  </g></g>
@@ -202,7 +202,7 @@ class USPSFlags::Core::TridentSpec
202
202
  #{long_trident_boundary_box(box_top, box_left, box_right)}
203
203
 
204
204
  <!-- Right -->
205
- #{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)} <!-- Hash to bottom -->
205
+ #{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)} <!-- Hash to bottom -->
206
206
 
207
207
  #{long_trident_left_arrow(box_top, box_bottom, box_left, box_right)}
208
208
  </g></g>
@@ -236,7 +236,7 @@ class USPSFlags::Core::TridentSpec
236
236
  def long_trident_left_arrow(box_top, box_bottom, box_left, box_right)
237
237
  <<~SVG
238
238
  <!-- Left -->
239
- #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, label_align: "middle")} <!-- Boundary height -->
239
+ #{USPSFlags::Helpers::SpecArrows.vertical(box_left-@trident_config[:bar_width]*1.5, box_top, box_bottom, box_left, box_left, label_offset: -USPSFlags::Config::BASE_FLY/30, label_offset_y: -USPSFlags::Config::BASE_FLY/4.5, label_align: "middle", fly: @fly, unit: @unit)} <!-- Boundary height -->
240
240
  SVG
241
241
  end
242
242
  end
@@ -1,3 +1,6 @@
1
+ # Custom errors.
2
+ #
3
+ # @private
1
4
  module USPSFlags::Errors
2
5
  class PNGGenerationError < StandardError
3
6
  def initialize(msg = "There was an error generating the PNG file.", svg: "")
@@ -95,13 +95,13 @@ class USPSFlags::Generate::Flag
95
95
  USPSFlags::Core::Tridents.cc(@flag_details[:type], trident_color: @trident_color)
96
96
  elsif vc?
97
97
  USPSFlags::Core::Tridents.vc(@flag_details[:type], trident_color: @trident_color)
98
- elsif cdr_or_dc?
98
+ elsif three?
99
99
  USPSFlags::Core::Tridents.three(@flag_details[:type], trident_color: @trident_color, field_color: @flag_details[:color])
100
- elsif ltc_or_dltc?
100
+ elsif two?
101
101
  USPSFlags::Core::Tridents.two(@flag_details[:type], trident_color: @trident_color, field_color: @flag_details[:color])
102
- elsif lt_or_dlt?
102
+ elsif offset?
103
103
  USPSFlags::Core::Tridents.offset(@flag_details[:type], field_color: @flag_details[:color], field: @field)
104
- elsif special_officer?
104
+ elsif special?
105
105
  special(@flag_details[:type], level: @flag_details[:level], field: @field)
106
106
  else
107
107
  USPSFlags::Core.trident(@flag_details[:type], field_color: @flag_details[:color])
@@ -131,19 +131,19 @@ class USPSFlags::Generate::Flag
131
131
  @flag_details[:type] == :n && @flag_details[:count] == 2
132
132
  end
133
133
 
134
- def cdr_or_dc?
134
+ def three?
135
135
  [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 3
136
136
  end
137
137
 
138
- def ltc_or_dltc?
138
+ def two?
139
139
  [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 2
140
140
  end
141
141
 
142
- def lt_or_dlt?
142
+ def offset?
143
143
  %w[LT DLT].include?(@rank)
144
144
  end
145
145
 
146
- def special_officer?
146
+ def special?
147
147
  [:a, :f, :fc, :pc].include?(@flag_details[:type])
148
148
  end
149
149
  end
@@ -54,14 +54,11 @@ class USPSFlags::Generate
54
54
  # @param [Boolean] zips Whether to create zip archives for all images created. Does not create a zip for skipped formats.
55
55
  # @param [Boolean] reset Whether to delete all previous files before generating new files.
56
56
  def all(svg: true, png: true, zips: true, reset: true)
57
- raise USPSFlags::Errors::StaticFilesGenerationError, "At least one argument switch must be true out of [svg, png, zips]." unless svg || png || zips
57
+ raise USPSFlags::Errors::StaticFilesGenerationError, "At least one argument switch must be true out of [svg, png, zips, reset]." unless svg || png || zips || reset
58
58
 
59
- remove_static_files if reset
60
- static_generation_header
61
59
  overall_start_time = Time.now
62
- USPSFlags::Helpers.valid_flags(:all).each do |flag|
63
- generate_static_images_for(flag, svg: svg, png: png)
64
- end
60
+ remove_static_files if reset
61
+ images(svg: svg, png: png) if svg || png
65
62
  zips(svg: svg, png: png) if zips
66
63
  USPSFlags::Helpers.log "\nTotal run time: #{Time.now - overall_start_time} s\n\n"
67
64
  end
@@ -76,6 +73,17 @@ class USPSFlags::Generate
76
73
  generate_zip("png") if png
77
74
  end
78
75
 
76
+ # Generate static image files.
77
+ #
78
+ # @param [Boolean] svg Generate static SVG images.
79
+ # @param [Boolean] png Generate static PNG images.
80
+ def images(svg: true, png: true)
81
+ static_generation_header
82
+ USPSFlags::Helpers.valid_flags(:all).each do |flag|
83
+ generate_static_images_for(flag, svg: svg, png: png)
84
+ end
85
+ end
86
+
79
87
  # Generate trident spec sheet as an SVG image.
80
88
  #
81
89
  # @param [String] outfile The path to save the SVG file to. If not set, prints to console.
@@ -83,8 +91,7 @@ class USPSFlags::Generate
83
91
  # @param [String] outfile The unit to append to all trident measurements.
84
92
  # @param [String] scale The image scale divisor factor.
85
93
  # @return [String] Returns the SVG data.
86
- def spec(outfile: nil, fly: nil, unit: nil, scale: nil)
87
- fly = fly.nil? ? USPSFlags::Config::BASE_FLY : fly
94
+ def spec(outfile: nil, fly: USPSFlags::Config::BASE_FLY, unit: nil, scale: nil)
88
95
  svg = ""
89
96
  svg << USPSFlags::Core.headers(scale: scale, title: "USPS Trident Specifications")
90
97
  svg << USPSFlags::Core.trident_spec(fly: fly, unit: unit)
@@ -103,8 +110,8 @@ class USPSFlags::Generate
103
110
  USPSFlags::Helpers.log "\n - Cleared previous files.\n"
104
111
  end
105
112
 
106
- def set_file_paths(flag)
107
- @svg_file = "#{USPSFlags::Config.flags_dir}/SVG/#{flag}.svg"
113
+ def set_file_paths
114
+ @svg_file = "#{USPSFlags::Config.flags_dir}/SVG/#{@flag}.svg"
108
115
  @png_file = @svg_file.gsub("/SVG/", "/PNG/").gsub(".svg", ".png")
109
116
  @svg_ins_file = @svg_file.gsub("/SVG/", "/SVG/insignia/")
110
117
  @png_ins_file = @svg_file.gsub("/SVG/", "/PNG/insignia/").gsub(".svg", ".png")
@@ -144,80 +151,96 @@ class USPSFlags::Generate
144
151
  def generate_static_images_for(flag, svg: true, png: true)
145
152
  start_time = Time.now
146
153
  # USPSFlags::Helpers.log " | | _ _ _ _ _ | \r".rjust(USPSFlags::Helpers.max_flag_name_length+31, " ")
147
- flag = flag.upcase
148
- USPSFlags::Helpers.log "#{flag.rjust(USPSFlags::Helpers.max_flag_name_length)} |"
154
+ @flag = flag.upcase
155
+ USPSFlags::Helpers.log "#{@flag.rjust(USPSFlags::Helpers.max_flag_name_length)} |"
149
156
 
150
- set_file_paths(flag)
157
+ set_file_paths
151
158
 
152
- svg ? generate_static_svg(flag) : USPSFlags::Helpers.log("-")
153
- png ? generate_static_png(flag) : USPSFlags::Helpers.log("- ")
159
+ svg ? generate_static_svg : USPSFlags::Helpers.log("-")
160
+ png ? generate_static_png : USPSFlags::Helpers.log("- ")
154
161
 
155
162
  run_time = (Time.now - start_time).round(4).to_s[(0..5)].ljust(6, "0")
156
163
  USPSFlags::Helpers.log " | #{run_time} s\n"
157
164
  end
158
165
 
159
- def generate_static_svg(flag)
166
+ def generate_static_svg
160
167
  USPSFlags::Helpers.log " "
161
- svg flag, outfile: @svg_file, scale: 1
168
+ svg @flag, outfile: @svg_file, scale: 1
162
169
  USPSFlags::Helpers.log "S"
163
- if USPSFlags::Helpers.valid_flags(:past).include?(flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
170
+ if USPSFlags::Helpers.valid_flags(:past).include?(@flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(@flag)
164
171
  USPSFlags::Helpers.log "-"
165
172
  else
166
- svg flag, field: false, outfile: @svg_ins_file, scale: 1
173
+ svg @flag, field: false, outfile: @svg_ins_file, scale: 1
167
174
  USPSFlags::Helpers.log "I"
168
175
  end
169
176
  end
170
177
 
171
- def generate_static_png(flag)
178
+ def generate_static_png
172
179
  USPSFlags::Helpers.log " | "
173
180
  generate_fullsize_png
174
- generate_fullsize_png_insignia(flag)
175
- generate_reduced_size_pngs(flag)
181
+ generate_fullsize_png_insignia
182
+ generate_reduced_size_pngs
176
183
  end
177
184
 
178
185
  def generate_fullsize_png
179
- png(File.read(@svg_file), outfile: @png_file) unless ::File.exist?(@png_file)
186
+ return if file_found?(@png_file)
187
+
188
+ png(File.read(@svg_file), outfile: @png_file)
180
189
  USPSFlags::Helpers.log "F"
181
190
  end
182
191
 
183
- def generate_fullsize_png_insignia(flag)
184
- if can_have_insignia?(flag)
185
- USPSFlags::Helpers.log "-"
186
- else
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
- end
192
+ def generate_fullsize_png_insignia
193
+ return if no_insignia?
194
+ return if file_found?(@png_ins_file)
191
195
 
192
- def can_have_insignia?(flag)
193
- USPSFlags::Helpers.valid_flags(:past).include?(flag) || !USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
196
+ png(File.read(@svg_ins_file), outfile: @png_ins_file, trim: true)
197
+ USPSFlags::Helpers.log "I"
194
198
  end
195
199
 
196
- def generate_reduced_size_pngs(flag)
200
+ def generate_reduced_size_pngs
197
201
  USPSFlags::Helpers.png_sizes.keys.each do |size|
198
- USPSFlags::Helpers.log(".") and next if ::File.exist?("#{USPSFlags::Config.flags_dir}/PNG/#{flag}.#{size}.png")
199
- size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: flag)
200
- generate_smaller_png(flag, size, size_key)
201
- generate_smaller_png_insignia(flag, size, size_key)
202
+ size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: @flag)
203
+ @sized_png_file = "#{USPSFlags::Config.flags_dir}/PNG/#{@flag}.#{@size_key}.png"
204
+ @sized_png_ins_file = @sized_png_file.gsub("/PNG/", "/PNG/insignia/")
205
+
206
+ generate_smaller_png(size, size_key)
207
+ generate_smaller_png_insignia(size, size_key)
202
208
  end
203
209
  end
204
210
 
205
- def generate_smaller_png(flag, size, size_key)
206
- USPSFlags::Helpers.resize_png(@png_ins_file, flag: flag, size: size, size_key: size_key) if USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
211
+ def generate_smaller_png(size, size_key)
212
+ return if file_found?(@sized_png_file)
213
+ return if too_big?(@png_file, size)
214
+
215
+ USPSFlags::Helpers.resize_png(@png_file, file: @flag, size: size, size_key: size_key)
207
216
  USPSFlags::Helpers.log USPSFlags::Helpers.png_sizes[size_key]
208
217
  end
209
218
 
210
- def generate_smaller_png_insignia(flag, size, size_key)
211
- if ::File.exist?(@png_ins_file) && ::File.exist?("#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size}.png")
212
- USPSFlags::Helpers.log "."
213
- elsif ::File.exist?(@png_ins_file) && MiniMagick::Image.open(@png_ins_file)[:width] > size && USPSFlags::Helpers.valid_flags(:insignia).include?(flag)
214
- USPSFlags::Helpers.resize_png(@png_ins_file, flag: flag, size: size, size_key: size_key)
215
- USPSFlags::Helpers.log "i"
216
- elsif ::File.exist?(@png_ins_file)
217
- USPSFlags::Helpers.log "+"
218
- else
219
- USPSFlags::Helpers.log "-"
220
- end
219
+ def generate_smaller_png_insignia(size, size_key)
220
+ return if no_insignia?
221
+ return if file_found?(@sized_png_ins_file)
222
+ return if too_big?(@png_ins_file, size)
223
+
224
+ USPSFlags::Helpers.resize_png(@png_ins_file, file: "insignia/#{@flag}", size: size, size_key: size_key)
225
+ USPSFlags::Helpers.log "i"
226
+ end
227
+
228
+ def no_insignia?
229
+ return false if USPSFlags::Helpers.valid_flags(:insignia).include?(@flag)
230
+ USPSFlags::Helpers.log "-"
231
+ true
232
+ end
233
+
234
+ def file_found?(file)
235
+ return false unless ::File.exist?(file)
236
+ USPSFlags::Helpers.log "."
237
+ true
238
+ end
239
+
240
+ def too_big?(file, size)
241
+ return false unless size > MiniMagick::Image.open(file)[:width]
242
+ USPSFlags::Helpers.log "+"
243
+ true
221
244
  end
222
245
  end
223
246
  end
@@ -8,9 +8,9 @@ class USPSFlags::Helpers::SpecArrows
8
8
  #
9
9
  # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
10
10
  # @private
11
- def vertical(x, top, bottom, pointer_top = nil, pointer_bottom = nil, label: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY/120), label_offset_y: 0, label_align: "left")
12
- load_common_config
13
- label, label_fraction = get_labels(bottom, top, label: label)
11
+ def vertical(x, top, bottom, pointer_top = nil, pointer_bottom = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY/120), label_offset_y: 0, label_align: "left")
12
+ load_common_config(fly)
13
+ label, label_fraction = get_labels(bottom, top)
14
14
  svg = ""
15
15
 
16
16
  svg << arrow_pointer(x, pointer_top, top, top) unless pointer_top.nil?
@@ -31,9 +31,9 @@ class USPSFlags::Helpers::SpecArrows
31
31
  #
32
32
  # This is used USPSFlags::Core.trident_spec, and should never need to be called directly.
33
33
  # @private
34
- def horizontal(y, left, right, pointer_left = nil, pointer_right = nil, label: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY/45), label_offset_x: 0, label_align: "middle")
35
- load_common_config
36
- label, label_fraction = get_labels(right, left, label: label)
34
+ def horizontal(y, left, right, pointer_left = nil, pointer_right = nil, fly: nil, unit: nil, label_offset: (USPSFlags::Config::BASE_FLY/45), label_offset_x: 0, label_align: "middle")
35
+ load_common_config(fly)
36
+ label, label_fraction = get_labels(right, left)
37
37
  svg = ""
38
38
 
39
39
  svg << arrow_pointer(left, left, pointer_left, y) unless pointer_left.nil?
@@ -51,13 +51,13 @@ class USPSFlags::Helpers::SpecArrows
51
51
  end
52
52
 
53
53
  private
54
- def load_common_config
54
+ def load_common_config(fly)
55
55
  @color = "#CCCCCC"
56
56
  @stroke_width = (USPSFlags::Config::BASE_FLY/600)
57
57
  @stroke_dash = "10, 10"
58
58
  @font_size = (USPSFlags::Config::BASE_FLY/60)
59
59
  @arrow_size = (USPSFlags::Config::BASE_FLY/120)
60
- @fly = USPSFlags::Config::BASE_FLY
60
+ @fly = fly || USPSFlags::Config::BASE_FLY
61
61
  end
62
62
 
63
63
  def arrow_pointer(x1, x2, y1, y2)
@@ -66,10 +66,8 @@ class USPSFlags::Helpers::SpecArrows
66
66
  SVG
67
67
  end
68
68
 
69
- def get_labels(a, b, label: nil)
70
- label = a - b if label.nil?
71
- label = label.to_i if label - label.to_i == 0
72
- label = Rational(label) * @fly / USPSFlags::Config::BASE_FLY
69
+ def get_labels(a, b)
70
+ label = (a - b) * Rational(@fly, USPSFlags::Config::BASE_FLY)
73
71
  if label == label.to_i
74
72
  label = label.to_i
75
73
  label_fraction = ""
@@ -44,13 +44,13 @@ class USPSFlags::Helpers
44
44
  #
45
45
  # This is used USPSFlags::Generate, and should never need to be called directly.
46
46
  # @private
47
- def resize_png(png_ins_file, flag:, size:, size_key:)
47
+ def resize_png(png_file, file:, size:, size_key:)
48
48
  MiniMagick::Tool::Convert.new do |convert|
49
49
  convert << "-background" << "none"
50
50
  convert << "-format" << "png"
51
51
  convert << "-resize" << "#{size}"
52
- convert << png_ins_file
53
- convert << "#{USPSFlags::Config.flags_dir}/PNG/insignia/#{flag}.#{size_key}.png"
52
+ convert << png_file
53
+ convert << "#{USPSFlags::Config.flags_dir}/PNG/#{file}.#{size_key}.png"
54
54
  end
55
55
  end
56
56
 
data/lib/usps_flags.rb CHANGED
@@ -107,9 +107,9 @@ class USPSFlags
107
107
  def png
108
108
  raise USPSFlags::Errors::PNGGenerationError, "A path must be set with png_file." if self.png_file.nil?
109
109
  svg_file_storage = self.svg_file
110
- self.svg_file ""
110
+ self.svg_file = ""
111
111
  USPSFlags::Generate.png(self.svg, outfile: self.png_file, trim: self.trim)
112
- self.svg_file svg_file_storage
112
+ self.svg_file = svg_file_storage
113
113
  self.png_file
114
114
  end
115
115
  end
Binary file
Binary file
Binary file
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'coveralls'
2
- Coveralls.wear!
3
1
  require 'bundler/setup'
4
2
  Bundler.setup
5
3
  require 'codeclimate-test-reporter'
@@ -37,4 +37,22 @@ describe USPSFlags::Config do
37
37
  expect(@config.use_larger_tridents).to eql(true)
38
38
  end
39
39
  end
40
+
41
+ describe "Rails configuration" do
42
+ before(:each) do
43
+ class Rails
44
+ def self.root
45
+ "tmp/rails_app"
46
+ end
47
+ end
48
+
49
+ @config = USPSFlags::Config.new do |config|
50
+ config.flags_dir = $tmp_flags_dir
51
+ end
52
+ end
53
+
54
+ it "should use the default Rails log directory" do
55
+ expect(USPSFlags::Config.log_path).to eql("tmp/rails_app/log")
56
+ end
57
+ end
40
58
  end
@@ -139,6 +139,10 @@ describe USPSFlags::Generate do
139
139
  it "should generate the trident specification sheet" do
140
140
  expect(USPSFlags::Generate.spec(outfile: "")).to include("<title>USPS Trident Specifications</title>")
141
141
  end
142
+
143
+ it "should generate the trident specification sheet with a fractional field size" do
144
+ expect(USPSFlags::Generate.spec(outfile: "", fly: 23.5)).to include("<title>USPS Trident Specifications</title>")
145
+ end
142
146
  end
143
147
 
144
148
  describe "png" do
@@ -151,25 +155,40 @@ describe USPSFlags::Generate do
151
155
  end
152
156
  end
153
157
 
158
+ describe "without an outfile set" do
159
+ it "should print SVG data to the console" do
160
+ expect(STDOUT).to receive(:puts).with(USPSFlags::Generate.svg("Lt", outfile: ""), "\n")
161
+ USPSFlags::Generate.svg("Lt")
162
+ end
163
+ end
164
+
154
165
  describe "static files" do
155
166
  it "should raise USPSFlags::Errors::StaticFilesGenerationError when not given any true arguments" do
156
- expect { USPSFlags::Generate.all(svg: false, png: false, zips: false) }.to raise_error(
157
- USPSFlags::Errors::StaticFilesGenerationError, "At least one argument switch must be true out of [svg, png, zips]."
167
+ expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: false) }.to raise_error(
168
+ USPSFlags::Errors::StaticFilesGenerationError, "At least one argument switch must be true out of [svg, png, zips, reset]."
158
169
  )
159
170
  end
160
171
 
161
- it "should not raise StaticFilesGenerationError while generating all static files" do
162
- expect { USPSFlags::Generate.all }.to_not raise_error(USPSFlags::Errors::StaticFilesGenerationError)
163
- end
164
-
165
172
  it "should raise USPSFlags::Errors::ZipGenerationError when not given any true arguments" do
166
173
  expect { USPSFlags::Generate.zips(svg: false, png: false) }.to raise_error(
167
174
  USPSFlags::Errors::ZipGenerationError, "At least one argument switch must be true out of [svg, png]."
168
175
  )
169
176
  end
170
177
 
171
- it "should not raise ZipGenerationError while generating zip files" do
172
- expect { USPSFlags::Generate.zips }.to_not raise_error(USPSFlags::Errors::ZipGenerationError)
178
+ it "should not raise an error while generating all static files" do
179
+ png_dir = "#{USPSFlags::Config.flags_dir}/PNG"
180
+ ::FileUtils.cp("spec/assets/1LT.thumb.png", "#{png_dir}/insignia/1LT.thumb.png")
181
+ ::FileUtils.cp("spec/assets/LT.png", "#{png_dir}/insignia/LT.png")
182
+ ::FileUtils.cp("spec/assets/FLT.png", "#{png_dir}/FLT.png")
183
+ expect { USPSFlags::Generate.all(reset: false) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError)
184
+ end
185
+
186
+ it "should not raise an error while clearing all static files" do
187
+ expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: true) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError)
188
+ end
189
+
190
+ it "should not raise an error while generating zip files" do
191
+ expect { USPSFlags::Generate.zips }.to_not raise_error # (USPSFlags::Errors::ZipGenerationError)
173
192
  end
174
193
  end
175
194
  end
@@ -144,9 +144,19 @@ describe USPSFlags do
144
144
  expect { @flag.png }.to raise_error(USPSFlags::Errors::PNGGenerationError, "A path must be set with png_file.")
145
145
  end
146
146
 
147
- it "should not raise PNGGenerationError with png_file set" do
148
- @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/LtC.png"
149
- expect { @flag.png }.to_not raise_error(USPSFlags::Errors::PNGGenerationError)
147
+ context "with png_file set" do
148
+ before(:each) do
149
+ @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/LtC.png"
150
+ ::FileUtils.mkdir_p("#{$tmp_alt_flags_dir}/PNG/")
151
+ end
152
+
153
+ it "should not raise PNGGenerationError with png_file set" do
154
+ expect { @flag.png }.to_not raise_error(USPSFlags::Errors::PNGGenerationError)
155
+ end
156
+
157
+ it "should return the value of png_file" do
158
+ expect(@flag.png).to eql("#{$tmp_alt_flags_dir}/PNG/LtC.png")
159
+ end
150
160
  end
151
161
  end
152
162
  end
data/usps_flags.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'usps_flags'
3
- s.version = '0.3.5'
4
- s.date = '2017-11-06'
3
+ s.version = '0.3.6'
4
+ s.date = '2017-11-07'
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'
data.tar.gz.sig CHANGED
Binary file
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.3.5
4
+ version: 0.3.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-06 00:00:00.000000000 Z
33
+ date: 2017-11-07 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: file_utils
@@ -219,6 +219,9 @@ files:
219
219
  - lib/usps_flags/helpers.rb
220
220
  - lib/usps_flags/helpers/builders.rb
221
221
  - lib/usps_flags/helpers/spec_arrows.rb
222
+ - spec/assets/1LT.thumb.png
223
+ - spec/assets/FLT.png
224
+ - spec/assets/LT.png
222
225
  - spec/rational_spec.rb
223
226
  - spec/spec_helper.rb
224
227
  - spec/usps_flags/config_spec.rb
@@ -254,6 +257,9 @@ signing_key:
254
257
  specification_version: 4
255
258
  summary: Flag generator for United States Power Squadrons
256
259
  test_files:
260
+ - spec/assets/1LT.thumb.png
261
+ - spec/assets/FLT.png
262
+ - spec/assets/LT.png
257
263
  - spec/rational_spec.rb
258
264
  - spec/spec_helper.rb
259
265
  - spec/usps_flags/config_spec.rb
metadata.gz.sig CHANGED
Binary file