usps_flags 0.3.1 → 0.3.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
  SHA1:
3
- metadata.gz: 2a60a3e26bbd93155f9878c9104c847ed3105eae
4
- data.tar.gz: c4be9514e8ee71ad53ced1a75c5d09bf17912f62
3
+ metadata.gz: 942e55ca17285fbdb9c4fe12e43228591bd8a8ab
4
+ data.tar.gz: 3bdfc5258b528ae4b69d759e18cadf42539cc18f
5
5
  SHA512:
6
- metadata.gz: 8f99ce4d839b26ab46949df7099895231f975047cbb4cd24bc26e88f9992b1a1a184e3f3a0459e9e5e1fe0edd0c6ed9042fe417aee6e12d05e9d0172c38f0abe
7
- data.tar.gz: 8bbb461aa04d65254d5ed582a3117b4dd1c4c3cbe9d45e388ec272cc00d7534ef50c984dcf0343908705995face90f9a15e9c388f1d19b3257b1476ffd4d64e8
6
+ metadata.gz: d55585eb11f710f9486a784f2867b31d1a78669baccf9f2c58cfbfbdbe5994c767c830b7ea03d7115e479c4fdd923193a6550df60a51bf0e3d2e09cd6ecb5c5c
7
+ data.tar.gz: ef662fc64315e1bb319cdbc8ef8a4745a222849f04f01d23a854fff098c042fefdf950c2f8bf17259b796b8265e9963c732427aa81d92e04ceeb2f1f7ae26a94
@@ -1 +1,3 @@
1
- 0�>�O� E으it��9��m����r|��9��N��Ix��ob���R��A(M���S4��%�JB&V~u!`����ZeeF��E�͉A��/G�Q3�ú ��&U՝ծП��2�"7�yMux��L��9 ���̌�N�4��5Un��v��lLCU�;Xoy������onƵʛ%����&�ڿˊ $`��7�a�6B
1
+ \����/�?���e��_^uU9v��ʭ��UI��$5�V�p2>�;�w�*?��8��w/�21S�^�7��#�ni[�֎���R�$H+�qb��vGa}R$?`�.��
2
+ �s��A��"F���xg��%Mw�?L�E.+m�p�"��R����d���
3
+ ��a]o�?� ,��'<�� ��?�B�px�űv=@#&�3�T�fs�{@{�A������n���鳰#2 ��S��x�~�c1����̎O�
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- Ҫ9L��B-\�\\�1}��P�� U4�d?c\��B��Ƨj����)U
1
+ o_&{ :U�����]D�ʵAYm|!�Vj��'�J����؉���*6*NCٖ�2��$=����Ė�MG����J�����٫�w���Loĵ{Pl��� |�0�wx6W�����S�%���@�V|���#8�*>F�Tߩ����t�� X�=&��^��I�d޳�@�2�FC���u<8�".���>�Ax嫊�]���Kb�q^�B�H5��[r�z��~�V�8��-?j_�Y�S1��8K�v��^�
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.3.0)
4
+ usps_flags (0.3.1)
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)
@@ -31,48 +31,61 @@ class USPSFlags::Core::Field
31
31
  def svg
32
32
  case @style
33
33
  when :regular
34
- <<~SVG
35
- <path d="M 0 0
36
- l #{@fly} 0
37
- l 0 #{@hoist}
38
- l -#{@fly} 0
39
- l 0 -#{@hoist}
40
- " fill="#{@color_code}" #{@border_svg}/>
41
- SVG
34
+ regular_field
42
35
  when :swallowtail
43
- <<~SVG
44
- <path d="M 0 0
45
- l #{@fly} #{@hoist/6}
46
- l -#{@fly/5} #{@hoist/3}
47
- l #{@fly/5} #{@hoist/3}
48
- l -#{@fly} #{@hoist/6}
49
- " fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
50
- SVG
36
+ swallowtail_field
51
37
  when :past
52
- <<~SVG
53
- <path d="M 0 0
54
- l #{@fly/2} #{@hoist*1/12}
55
- l 0 #{@hoist*10/12}
56
- l -#{@fly/2} #{@hoist*1/12}
57
- " fill="#{@color_code}" />
58
- <path d="M #{@fly/2} #{@hoist*1/12}
59
- l #{@fly/4} #{@hoist*1/24}
60
- l 0 #{@hoist*9/12}
61
- l -#{@fly/4} #{@hoist*1/24}
62
- " fill="#{@past_mid_color}" />
63
- <path d="M #{@fly*3/4} #{@hoist*3/24}
64
- l #{@fly/4} #{@hoist*1/24}
65
- l -#{@fly/5} #{@hoist/3}
66
- l #{@fly/5} #{@hoist/3}
67
- l -#{@fly/4} #{@hoist*1/24}
68
- " fill="#{@past_tail_color}" />
69
- <path d="M 0 0
70
- l #{@fly} #{@hoist/6}
71
- l -#{@fly/5} #{@hoist/3}
72
- l #{@fly/5} #{@hoist/3}
73
- l -#{@fly} #{@hoist/6}
74
- " fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
75
- SVG
38
+ past_field
76
39
  end
77
40
  end
41
+
42
+ private
43
+ def regular_field
44
+ <<~SVG
45
+ <path d="M 0 0
46
+ l #{@fly} 0
47
+ l 0 #{@hoist}
48
+ l -#{@fly} 0
49
+ l 0 -#{@hoist}
50
+ " fill="#{@color_code}" #{@border_svg}/>
51
+ SVG
52
+ end
53
+
54
+ def swallowtail_field
55
+ <<~SVG
56
+ <path d="M 0 0
57
+ l #{@fly} #{@hoist/6}
58
+ l -#{@fly/5} #{@hoist/3}
59
+ l #{@fly/5} #{@hoist/3}
60
+ l -#{@fly} #{@hoist/6}
61
+ " fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
62
+ SVG
63
+ end
64
+
65
+ def past_field
66
+ <<~SVG
67
+ <path d="M 0 0
68
+ l #{@fly/2} #{@hoist*1/12}
69
+ l 0 #{@hoist*10/12}
70
+ l -#{@fly/2} #{@hoist*1/12}
71
+ " fill="#{@color_code}" />
72
+ <path d="M #{@fly/2} #{@hoist*1/12}
73
+ l #{@fly/4} #{@hoist*1/24}
74
+ l 0 #{@hoist*9/12}
75
+ l -#{@fly/4} #{@hoist*1/24}
76
+ " fill="#{@past_mid_color}" />
77
+ <path d="M #{@fly*3/4} #{@hoist*3/24}
78
+ l #{@fly/4} #{@hoist*1/24}
79
+ l -#{@fly/5} #{@hoist/3}
80
+ l #{@fly/5} #{@hoist/3}
81
+ l -#{@fly/4} #{@hoist*1/24}
82
+ " fill="#{@past_tail_color}" />
83
+ <path d="M 0 0
84
+ l #{@fly} #{@hoist/6}
85
+ l -#{@fly/5} #{@hoist/3}
86
+ l #{@fly/5} #{@hoist/3}
87
+ l -#{@fly} #{@hoist/6}
88
+ " fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
89
+ SVG
90
+ end
78
91
  end
@@ -88,17 +88,8 @@ class USPSFlags::Generate
88
88
  # @param [Boolean] png Generate zip archive of PNG images.
89
89
  def zips(svg: true, png: true)
90
90
  raise USPSFlags::Errors::ZipGenerationError, "At least one argument switch must be true out of [svg, png]." unless svg || png
91
- begin
92
- generate_zip("svg") if svg
93
- rescue Errno::EACCES => e
94
- raise USPSFlags::Errors::ZipGenerationError, type: :svg, cause: e
95
- end
96
-
97
- begin
98
- generate_zip("png") if png
99
- rescue Errno::EACCES => e
100
- raise USPSFlags::Errors::ZipGenerationError, type: :png, cause: e
101
- end
91
+ generate_zip("svg") if svg
92
+ generate_zip("png") if png
102
93
  rescue => e
103
94
  raise e if e.is_a?(USPSFlags::Errors::ZipGenerationError)
104
95
  raise USPSFlags::Errors::ZipGenerationError, cause: e
@@ -6,37 +6,20 @@ class USPSFlags::Generate::Flag
6
6
  class << self
7
7
  def officer(rank: nil, width: USPSFlags::Config::BASE_FLY, outfile: nil, scale: nil, field: true)
8
8
  raise "Error: No rank specified." if rank.nil?
9
- rank = rank.to_s.upcase
9
+ @rank = rank.to_s.upcase
10
+ @field = field
10
11
 
11
12
  svg = ""
12
- svg << USPSFlags::Core.headers(scale: scale, title: rank)
13
-
14
- rank.slice!(0) if !field && USPSFlags::Helpers.valid_flags(:past).include?(rank)
15
- rank = "CDR" if rank == "C"
16
-
17
- flag_details = USPSFlags::Helpers.flag_details(rank)
18
- trident_color = field ? :white : flag_details[:color]
19
-
20
- svg << USPSFlags::Core.field(style: flag_details[:style], color: flag_details[:color]) if field
21
- svg << "<g transform=\"translate(-150, 400)\"><g transform=\"scale(0.58333)\">" if flag_details[:style] == :past
22
-
23
- if flag_details[:type] == :n && flag_details[:count] == 3
24
- svg << USPSFlags::Core::Tridents.cc(flag_details[:type], trident_color: trident_color)
25
- elsif flag_details[:type] == :n && flag_details[:count] == 2
26
- svg << USPSFlags::Core::Tridents.vc(flag_details[:type], trident_color: trident_color)
27
- elsif [:s, :d].include?(flag_details[:type]) && flag_details[:count] == 3
28
- svg << USPSFlags::Core::Tridents.three(flag_details[:type], trident_color: trident_color, field_color: flag_details[:color])
29
- elsif [:s, :d].include?(flag_details[:type]) && flag_details[:count] == 2
30
- svg << USPSFlags::Core::Tridents.two(flag_details[:type], trident_color: trident_color, field_color: flag_details[:color])
31
- elsif [:s, :d, :stf, :n].include?(flag_details[:type]) && %w[LT DLT].include?(rank)
32
- svg << USPSFlags::Core::Tridents.offset(flag_details[:type], field_color: flag_details[:color], field: field)
33
- elsif [:a, :f, :fc, :pc].include?(flag_details[:type])
34
- svg << special(flag_details[:type], level: flag_details[:level], field: field)
35
- else
36
- svg << USPSFlags::Core.trident(flag_details[:type], field_color: flag_details[:color])
37
- end
13
+ svg << USPSFlags::Core.headers(scale: scale, title: @rank)
14
+
15
+ modify_rank_for_insignia
16
+ @flag_details = USPSFlags::Helpers.flag_details(@rank)
17
+ @trident_color = @field ? :white : @flag_details[:color]
38
18
 
39
- svg << "</g></g>" if flag_details[:style] == :past
19
+ svg << USPSFlags::Core.field(style: @flag_details[:style], color: @flag_details[:color]) if @field
20
+ svg << "<g transform=\"translate(-150, 400)\"><g transform=\"scale(0.58333)\">" if @flag_details[:style] == :past
21
+ svg << get_officer_flag
22
+ svg << "</g></g>" if @flag_details[:style] == :past
40
23
  svg << USPSFlags::Core.footer
41
24
 
42
25
  USPSFlags::Helpers.output(svg, outfile: outfile)
@@ -111,5 +94,29 @@ class USPSFlags::Generate::Flag
111
94
 
112
95
  USPSFlags::Helpers.output(svg, outfile: outfile)
113
96
  end
97
+
98
+ private
99
+ def get_officer_flag
100
+ if @flag_details[:type] == :n && @flag_details[:count] == 3
101
+ USPSFlags::Core::Tridents.cc(@flag_details[:type], trident_color: @trident_color)
102
+ elsif @flag_details[:type] == :n && @flag_details[:count] == 2
103
+ USPSFlags::Core::Tridents.vc(@flag_details[:type], trident_color: @trident_color)
104
+ elsif [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 3
105
+ USPSFlags::Core::Tridents.three(@flag_details[:type], trident_color: @trident_color, field_color: @flag_details[:color])
106
+ elsif [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 2
107
+ USPSFlags::Core::Tridents.two(@flag_details[:type], trident_color: @trident_color, field_color: @flag_details[:color])
108
+ elsif [:s, :d, :stf, :n].include?(@flag_details[:type]) && %w[LT DLT].include?(@rank)
109
+ USPSFlags::Core::Tridents.offset(@flag_details[:type], field_color: @flag_details[:color], field: @field)
110
+ elsif [:a, :f, :fc, :pc].include?(@flag_details[:type])
111
+ special(@flag_details[:type], level: @flag_details[:level], field: @field)
112
+ else
113
+ USPSFlags::Core.trident(@flag_details[:type], field_color: @flag_details[:color])
114
+ end
115
+ end
116
+
117
+ def modify_rank_for_insignia
118
+ @rank.slice!(0) if !@field && USPSFlags::Helpers.valid_flags(:past).include?(@rank)
119
+ @rank = "CDR" if @rank == "C"
120
+ end
114
121
  end
115
122
  end
@@ -14,52 +14,8 @@ class USPSFlags::Helpers
14
14
  # @option type [Symbol] :us US flag
15
15
  # @return [Array] Valid options for flag generation (based on the provided type).
16
16
  def valid_flags(type = :all)
17
- squadron_past = %w[PLTC PC]
18
- squadron_elected = %w[1LT LTC CDR]
19
- squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT]
20
- district_past = %w[PDLTC PDC]
21
- district_elected = %w[D1LT DLTC DC]
22
- district_swallowtail = %w[DLT DAIDE DFLT]
23
- national_past = %w[PSTFC PRC PVC PCC]
24
- national_elected = %w[NAIDE NFLT STFC RC VC CC]
25
- special = %w[CRUISE OIC ENSIGN WHEEL]
26
- us = %w[US]
27
-
28
- squadron = squadron_past + squadron_elected + squadron_swallowtail
29
- district = district_past + district_elected + district_swallowtail
30
- national = national_past + national_elected
31
- past = squadron_past + district_past + national_past
32
-
33
- case type
34
- when :all
35
- squadron + district + national + special + us
36
- when :officer
37
- squadron + district + national
38
- when :insignia
39
- squadron + district + national - past
40
- when :squadron
41
- squadron
42
- when :district
43
- district
44
- when :national
45
- national
46
- when :special
47
- special
48
- when :us
49
- us
50
- when :past
51
- past
52
- when :swallowtail
53
- past + squadron_swallowtail + district_swallowtail
54
- when :bridge
55
- squadron_elected.last(2) + squadron_past.last(2) +
56
- district_elected.last(2) + district_past.last(2) +
57
- national_elected.last(2) + national_past.last(2)
58
- when :command
59
- [squadron_elected.last, squadron_past.last,
60
- district_elected.last, district_past.last,
61
- national_elected.last, national_past.last]
62
- end
17
+ load_valid_flags
18
+ valid_flags_for(type)
63
19
  end
64
20
 
65
21
  # Gets the maximum length among valid flags.
@@ -165,6 +121,50 @@ class USPSFlags::Helpers
165
121
  end
166
122
 
167
123
  private
124
+ def load_valid_flags
125
+ @squadron_past = %w[PLTC PC]
126
+ @squadron_elected = %w[1LT LTC CDR]
127
+ @squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT]
128
+ @district_past = %w[PDLTC PDC]
129
+ @district_elected = %w[D1LT DLTC DC]
130
+ @district_swallowtail = %w[DLT DAIDE DFLT]
131
+ @national_past = %w[PSTFC PRC PVC PCC]
132
+ @national_elected = %w[NAIDE NFLT STFC RC VC CC]
133
+ @special = %w[CRUISE OIC ENSIGN WHEEL]
134
+ @us = %w[US]
135
+
136
+ @past = @squadron_past + @district_past + @national_past
137
+ @squadron = @squadron_past + @squadron_elected + @squadron_swallowtail
138
+ @district = @district_past + @district_elected + @district_swallowtail
139
+ @national = @national_past + @national_elected
140
+ @officer = @squadron + @district + @national
141
+ end
142
+
143
+ def valid_flags_for(type)
144
+ {
145
+ special: @special,
146
+ us: @us,
147
+
148
+ squadron: @squadron,
149
+ district: @district,
150
+ national: @national,
151
+ past: @past,
152
+
153
+ all: @officer + @special + @us,
154
+ officer: @officer,
155
+ insignia: @officer - @past,
156
+ swallowtail: @past + @squadron_swallowtail + @district_swallowtail,
157
+
158
+ bridge: @squadron_elected.last(2) + @squadron_past.last(2) +
159
+ @district_elected.last(2) + @district_past.last(2) +
160
+ @national_elected.last(2) + @national_past.last(2),
161
+
162
+ command: [@squadron_elected.last, @squadron_past.last,
163
+ @district_elected.last, @district_past.last,
164
+ @national_elected.last, @national_past.last]
165
+ }[type]
166
+ end
167
+
168
168
  def flag_style(rank)
169
169
  if valid_flags(:past).include?(rank)
170
170
  :past
@@ -188,18 +188,12 @@ class USPSFlags::Helpers
188
188
  end
189
189
 
190
190
  def flag_level(rank)
191
- if rank == "DAIDE"
192
- :d
193
- elsif rank == "NAIDE"
191
+ if rank.match /N.*/
194
192
  :n
193
+ elsif rank.match /D.*/
194
+ :d
195
195
  elsif rank == "FLT"
196
196
  :s
197
- elsif rank == "DFLT"
198
- :d
199
- elsif rank == "NFLT"
200
- :n
201
- else
202
- nil
203
197
  end
204
198
  end
205
199
 
@@ -218,19 +212,19 @@ class USPSFlags::Helpers
218
212
  :pc
219
213
  elsif rank == "FLEETCAP"
220
214
  :fc
221
- elsif rank == "DAIDE"
222
- :a
223
- elsif rank == "NAIDE"
224
- :a
225
- elsif rank == "FLT"
226
- :f
227
- elsif rank == "DFLT"
228
- :f
229
- elsif rank == "NFLT"
230
- :f
231
215
  elsif rank == "STFC"
232
216
  :stf
233
- elsif valid_flags(:squadron).include?(rank)
217
+ elsif rank.match /.AIDE/
218
+ :a
219
+ elsif rank.match /.?FLT/
220
+ :f
221
+ else
222
+ get_line_flag_level(rank)
223
+ end
224
+ end
225
+
226
+ def get_line_flag_level(rank)
227
+ if valid_flags(:squadron).include?(rank)
234
228
  :s
235
229
  elsif valid_flags(:district).include?(rank)
236
230
  :d
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'usps_flags'
3
- s.version = '0.3.1'
3
+ s.version = '0.3.2'
4
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.'
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
metadata.gz.sig CHANGED
Binary file