usps_flags 0.5.0 → 0.5.1

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +22 -11
  3. data/.travis.yml +1 -1
  4. data/Gemfile.lock +5 -2
  5. data/README.md +6 -0
  6. data/lib/usps_flags.rb +35 -44
  7. data/lib/usps_flags/config.rb +89 -87
  8. data/lib/usps_flags/core.rb +44 -42
  9. data/lib/usps_flags/core/ensign.rb +53 -49
  10. data/lib/usps_flags/core/field.rb +96 -92
  11. data/lib/usps_flags/core/footer.rb +9 -5
  12. data/lib/usps_flags/core/headers.rb +58 -48
  13. data/lib/usps_flags/core/icons.rb +11 -7
  14. data/lib/usps_flags/core/icons/anchor.rb +62 -56
  15. data/lib/usps_flags/core/icons/binoculars.rb +21 -15
  16. data/lib/usps_flags/core/icons/lighthouse.rb +28 -22
  17. data/lib/usps_flags/core/icons/star.rb +21 -15
  18. data/lib/usps_flags/core/icons/trident.rb +136 -127
  19. data/lib/usps_flags/core/icons/trident_parts/hashes.rb +62 -55
  20. data/lib/usps_flags/core/icons/trumpet.rb +34 -28
  21. data/lib/usps_flags/core/pennant.rb +50 -46
  22. data/lib/usps_flags/core/trident_spec.rb +135 -131
  23. data/lib/usps_flags/core/trident_specs.rb +11 -7
  24. data/lib/usps_flags/core/trident_specs/base.rb +36 -26
  25. data/lib/usps_flags/core/trident_specs/circle.rb +36 -30
  26. data/lib/usps_flags/core/trident_specs/delta.rb +41 -30
  27. data/lib/usps_flags/core/trident_specs/header.rb +56 -50
  28. data/lib/usps_flags/core/trident_specs/horizontal.rb +80 -0
  29. data/lib/usps_flags/core/trident_specs/long.rb +41 -25
  30. data/lib/usps_flags/core/trident_specs/overlay.rb +40 -0
  31. data/lib/usps_flags/core/trident_specs/short.rb +30 -156
  32. data/lib/usps_flags/core/trident_specs/vertical.rb +108 -0
  33. data/lib/usps_flags/core/tridents.rb +54 -50
  34. data/lib/usps_flags/core/us.rb +40 -44
  35. data/lib/usps_flags/core/wheel.rb +7 -3
  36. data/lib/usps_flags/errors.rb +25 -23
  37. data/lib/usps_flags/generate.rb +111 -107
  38. data/lib/usps_flags/generate/flag.rb +160 -157
  39. data/lib/usps_flags/generate/generator_methods.rb +139 -0
  40. data/lib/usps_flags/generate/helper_methods.rb +88 -0
  41. data/lib/usps_flags/helpers.rb +163 -165
  42. data/lib/usps_flags/helpers/builders.rb +92 -85
  43. data/lib/usps_flags/helpers/spec_arrows.rb +127 -123
  44. data/lib/usps_flags/helpers/valid_flags.rb +45 -41
  45. data/lib/usps_flags/rational.rb +35 -0
  46. data/spec/usps_flags/config_spec.rb +17 -10
  47. data/spec/usps_flags/core_spec.rb +31 -31
  48. data/spec/usps_flags/generate_spec.rb +76 -73
  49. data/spec/usps_flags/helpers_spec.rb +8 -8
  50. data/spec/usps_flags/rational_spec.rb +17 -0
  51. data/spec/usps_flags_spec.rb +19 -21
  52. data/usps_flags.gemspec +7 -6
  53. metadata +34 -10
  54. data/lib/rational.rb +0 -39
  55. data/lib/usps_flags/generate/private.rb +0 -199
  56. data/spec/rational_spec.rb +0 -19
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: false
2
+
3
+ # Private methods for USPSFlags::Generator.
4
+ #
5
+ # These methods should never need to be called directly.
6
+ # @private
7
+ class USPSFlags
8
+ class Generate
9
+ module GeneratorMethods
10
+ # This module defined no public methods
11
+ def _; end
12
+
13
+ private
14
+
15
+ def static_generation_header
16
+ puts "\nSVGs generate a single file.",
17
+ 'PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.',
18
+ 'Corresponding rank insignia (including smaller sizes) are also generated, as appropriate.'
19
+ USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags.configuration.flags_dir}\n"
20
+ USPSFlags::Helpers.log "\n#{Time.now.strftime('%Y%m%d.%H%M%S%z')} – Generating static files...\n\n"
21
+ length = USPSFlags::Helpers.max_flag_name_length + 31
22
+ USPSFlags::Helpers.log "Flag | SVG | PNG | Run time\n".rjust(length),
23
+ "\n".rjust(USPSFlags::Helpers.max_flag_name_length + 32, '-')
24
+ end
25
+
26
+ def generate_zip(type)
27
+ no_dir = [USPSFlags::Errors::ZipGenerationError, 'Flags directory not found.']
28
+ raise(*no_dir) unless ::Dir.exist?("#{USPSFlags.configuration.flags_dir}/ZIP")
29
+
30
+ zip = "#{USPSFlags.configuration.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
31
+ ::File.delete(zip) if ::File.exist?(zip)
32
+ write_zip_file(zip, type)
33
+
34
+ puts "Generated #{type.upcase} Zip"
35
+ end
36
+
37
+ def write_zip_file(zip, type)
38
+ ::Zip::File.open(zip, ::Zip::File::CREATE) do |z|
39
+ ::Dir.glob("#{USPSFlags.configuration.flags_dir}/#{type.upcase}/**/*").each do |f|
40
+ add_to_zip(z, f)
41
+ end
42
+ end
43
+ end
44
+
45
+ def add_to_zip(z, f)
46
+ filename = f.split('/').last
47
+ filename = "insignia/#{filename}" if f.split('/').last(2).first == 'insignia'
48
+ z.add(filename, f)
49
+ end
50
+
51
+ def generate_static_images_for(flag, svg: true, png: true)
52
+ run_time = track_time(simple: true) do
53
+ @flag = flag.upcase
54
+ USPSFlags::Helpers.log "#{@flag.rjust(USPSFlags::Helpers.max_flag_name_length)} |"
55
+ set_file_paths
56
+ generate_requested_images(svg, png)
57
+ end
58
+
59
+ USPSFlags::Helpers.log " | #{run_time.round(4).to_s[(0..5)].ljust(6, '0')} s\n"
60
+ end
61
+
62
+ def generate_requested_images(svg, png)
63
+ svg ? generate_static_svg : USPSFlags::Helpers.log('-')
64
+ png ? generate_static_png : USPSFlags::Helpers.log('- ')
65
+ end
66
+
67
+ def generate_static_svg
68
+ USPSFlags::Helpers.log ' '
69
+
70
+ generate_regular_svg
71
+ generate_insignia_svg
72
+ end
73
+
74
+ def generate_regular_svg
75
+ return if file_found?(@svg_file)
76
+
77
+ svg @flag, outfile: @svg_file, scale: 1
78
+ USPSFlags::Helpers.log 'S'
79
+ end
80
+
81
+ def generate_insignia_svg
82
+ return if no_insignia?
83
+
84
+ svg @flag, field: false, outfile: @svg_ins_file, scale: 1
85
+ USPSFlags::Helpers.log 'I'
86
+ end
87
+
88
+ def generate_static_png
89
+ USPSFlags::Helpers.log ' | '
90
+ generate_fullsize_png
91
+ generate_fullsize_png_insignia
92
+ generate_reduced_size_pngs
93
+ end
94
+
95
+ def generate_fullsize_png
96
+ return if file_found?(@png_file)
97
+
98
+ png(File.read(@svg_file), outfile: @png_file)
99
+ USPSFlags::Helpers.log 'F'
100
+ end
101
+
102
+ def generate_fullsize_png_insignia
103
+ return if no_insignia?
104
+ return if file_found?(@png_ins_file)
105
+
106
+ png(File.read(@svg_ins_file), outfile: @png_ins_file, trim: true)
107
+ USPSFlags::Helpers.log 'I'
108
+ end
109
+
110
+ def generate_reduced_size_pngs
111
+ USPSFlags::Helpers.png_sizes.keys.each do |size|
112
+ size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: @flag)
113
+ @sized_png_file = "#{USPSFlags.configuration.flags_dir}/PNG/#{@flag}.#{size_key}.png"
114
+ @sized_png_ins_file = @sized_png_file.gsub('/PNG/', '/PNG/insignia/')
115
+
116
+ generate_smaller_png(size, size_key)
117
+ generate_smaller_png_insignia(size, size_key)
118
+ end
119
+ end
120
+
121
+ def generate_smaller_png(size, size_key)
122
+ return if file_found?(@sized_png_file)
123
+ return if too_big?(@png_file, size)
124
+
125
+ USPSFlags::Helpers.resize_png(@png_file, file: @flag, size: size, size_key: size_key)
126
+ USPSFlags::Helpers.log USPSFlags::Helpers.png_sizes[size_key]
127
+ end
128
+
129
+ def generate_smaller_png_insignia(size, size_key)
130
+ return if no_insignia?
131
+ return if file_found?(@sized_png_ins_file)
132
+ return if too_big?(@png_ins_file, size)
133
+
134
+ USPSFlags::Helpers.resize_png(@png_ins_file, file: "insignia/#{@flag}", size: size, size_key: size_key)
135
+ USPSFlags::Helpers.log 'i'
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: false
2
+
3
+ # Private methods for USPSFlags::Generator.
4
+ #
5
+ # These methods should never need to be called directly.
6
+ # @private
7
+ class USPSFlags
8
+ class Generate
9
+ module HelperMethods
10
+ # This module defined no public methods
11
+ def _; end
12
+
13
+ private
14
+
15
+ def remove_static_files
16
+ %w[SVG PNG ZIP].each do |dir|
17
+ dir_path = "#{USPSFlags.configuration.flags_dir}/#{dir}"
18
+ ::FileUtils.rm_rf(::Dir.glob("#{dir_path}/*")) if ::Dir.exist?(dir_path)
19
+ end
20
+
21
+ ['SVG/insignia', 'PNG/insignia'].each do |dir|
22
+ ::FileUtils.mkdir_p("#{USPSFlags.configuration.flags_dir}/#{dir}")
23
+ end
24
+
25
+ USPSFlags::Helpers.log "\n - Cleared previous files.\n"
26
+ end
27
+
28
+ def set_file_paths
29
+ @svg_file = "#{USPSFlags.configuration.flags_dir}/SVG/#{@flag}.svg"
30
+ @png_file = @svg_file.gsub('/SVG/', '/PNG/').gsub('.svg', '.png')
31
+ @svg_ins_file = @svg_file.gsub('/SVG/', '/SVG/insignia/')
32
+ @png_ins_file = @svg_file.gsub('/SVG/', '/PNG/insignia/').gsub('.svg', '.png')
33
+ [@svg_file, @png_file, @svg_ins_file, @png_ins_file]
34
+ end
35
+
36
+ def set_temp_svg(svg)
37
+ @temp_svg_path = "#{USPSFlags.configuration.flags_dir}/temp.svg"
38
+ temp_svg = ::File.new(@temp_svg_path, 'w+')
39
+ temp_svg.write(svg)
40
+ temp_svg.flush
41
+ @temp_svg_path
42
+ end
43
+
44
+ def delete_temp_svg?
45
+ !@temp_svg_path.to_s.empty? && ::File.exist?(@temp_svg_path)
46
+ end
47
+
48
+ def any_all_arg?(svg, png, zips, reset)
49
+ svg || png || zips || reset
50
+ end
51
+
52
+ def all_arg_error
53
+ raise(
54
+ USPSFlags::Errors::StaticFilesGenerationError,
55
+ 'At least one argument switch must be true out of [svg, png, zips, reset].'
56
+ )
57
+ end
58
+
59
+ def track_time(simple: false)
60
+ overall_start_time = Time.now
61
+ yield
62
+ end_time = Time.now - overall_start_time
63
+ simple ? end_time : USPSFlags::Helpers.log("\nTotal run time: #{end_time} s\n\n")
64
+ end
65
+
66
+ def no_insignia?
67
+ return false if USPSFlags::Helpers.valid_flags(:insignia).include?(@flag)
68
+
69
+ USPSFlags::Helpers.log '-'
70
+ true
71
+ end
72
+
73
+ def file_found?(file)
74
+ return false unless ::File.exist?(file)
75
+
76
+ USPSFlags::Helpers.log '.'
77
+ true
78
+ end
79
+
80
+ def too_big?(file, size)
81
+ return false unless size > MiniMagick::Image.open(file)[:width]
82
+
83
+ USPSFlags::Helpers.log '+'
84
+ true
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,199 +1,197 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # Container class for helper methods.
4
- class USPSFlags::Helpers
5
- require 'usps_flags/helpers/valid_flags'
6
-
7
- class << self
8
- # Valid options for flag generation.
9
- #
10
- # @param [Symbol] type Specify subset of flags.
11
- # @option type [Symbol] :all All flags
12
- # @option type [Symbol] :officer Officer flags
13
- # @option type [Symbol] :insignia Insignia-eligible officer flags (no past officers)
14
- # @option type [Symbol] :squadron Squadron-level officer flags
15
- # @option type [Symbol] :district District-level officer flags
16
- # @option type [Symbol] :national National-level officer flags
17
- # @option type [Symbol] :special Special flags
18
- # @option type [Symbol] :us US flag
19
- # @return [Array] Valid options for flag generation (based on the provided type).
20
- def valid_flags(type = :all)
21
- USPSFlags::Helpers::ValidFlags.load_valid_flags
22
- USPSFlags::Helpers::ValidFlags.load_special_flags
23
- USPSFlags::Helpers::ValidFlags.load_valid_flag_groups
24
- USPSFlags::Helpers::ValidFlags.valid_flags_for(type)
25
- end
26
-
27
- # Resizes and saves a PNG image.
28
- #
29
- # One of the params [file, outfile] is required, and outfile takes precedence.
30
- #
31
- # @param [String] png_file Path to the PNG file to resize.
32
- # @param [String] file Abbreviated key for the output file (e.g. "LTC", "insignia/FLT").
33
- # @param [String] outfile Path to the output file.
34
- # @param [String] size Actual size to output as.
35
- # @param [String] size_key Size suffix to attach to the file name.
36
- def resize_png(png_file, file: nil, outfile: nil, size:, size_key: nil)
37
- raise USPSFlags::Errors::PNGConversionError if outfile.nil? && file.nil?
38
- raise USPSFlags::Errors::PNGConversionError if outfile.nil? && size_key.nil?
39
-
40
- output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
41
- resize_convert(size, png_file, output_file_name)
42
- end
4
+ class USPSFlags
5
+ class Helpers
6
+ require 'usps_flags/helpers/valid_flags'
7
+
8
+ class << self
9
+ # Valid options for flag generation.
10
+ #
11
+ # @param [Symbol] type Specify subset of flags.
12
+ # @option type [Symbol] :all All flags
13
+ # @option type [Symbol] :officer Officer flags
14
+ # @option type [Symbol] :insignia Insignia-eligible officer flags (no past officers)
15
+ # @option type [Symbol] :squadron Squadron-level officer flags
16
+ # @option type [Symbol] :district District-level officer flags
17
+ # @option type [Symbol] :national National-level officer flags
18
+ # @option type [Symbol] :special Special flags
19
+ # @option type [Symbol] :us US flag
20
+ # @return [Array] Valid options for flag generation (based on the provided type).
21
+ def valid_flags(type = :all)
22
+ USPSFlags::Helpers::ValidFlags.load_valid_flags
23
+ USPSFlags::Helpers::ValidFlags.load_special_flags
24
+ USPSFlags::Helpers::ValidFlags.load_valid_flag_groups
25
+ USPSFlags::Helpers::ValidFlags.valid_flags_for(type)
26
+ end
43
27
 
44
- # Gets the maximum length among valid flags.
45
- #
46
- # This is used USPSFlags::Generate, and should never need to be called directly.
47
- # @private
48
- def max_flag_name_length
49
- valid_flags(:all).map(&:length).max
50
- end
28
+ # Resizes and saves a PNG image.
29
+ #
30
+ # One of the params [file, outfile] is required, and outfile takes precedence.
31
+ #
32
+ # @param [String] png_file Path to the PNG file to resize.
33
+ # @param [String] file Abbreviated key for the output file (e.g. "LTC", "insignia/FLT").
34
+ # @param [String] outfile Path to the output file.
35
+ # @param [String] size Actual size to output as.
36
+ # @param [String] size_key Size suffix to attach to the file name.
37
+ def resize_png(png_file, file: nil, outfile: nil, size:, size_key: nil)
38
+ raise USPSFlags::Errors::PNGConversionError if outfile.nil? && file.nil?
39
+ raise USPSFlags::Errors::PNGConversionError if outfile.nil? && size_key.nil?
40
+
41
+ output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
42
+ resize_convert(size, png_file, output_file_name)
43
+ end
51
44
 
52
- # Gets the generation details for the given rank.
53
- #
54
- # This is used USPSFlags::Generate, and should never need to be called directly.
55
- # @private
56
- def flag_details(rank)
57
- {
58
- style: flag_style(rank),
59
- color: flag_color(rank),
60
- type: flag_type(rank),
61
- level: flag_level(rank),
62
- count: flag_count(rank)
63
- }
64
- end
45
+ # Gets the maximum length among valid flags.
46
+ #
47
+ # This is used USPSFlags::Generate, and should never need to be called directly.
48
+ # @private
49
+ def max_flag_name_length
50
+ valid_flags(:all).map(&:length).max
51
+ end
65
52
 
66
- # Image sizes for generated PNG images.
67
- #
68
- # This is used USPSFlags::Generate, and should never need to be called directly.
69
- # @private
70
- def png_sizes
71
- { 1500 => 'H', 1000 => 'K', 500 => 'D', 'thumb' => 'T' }
72
- end
53
+ # Gets the generation details for the given rank.
54
+ #
55
+ # This is used USPSFlags::Generate, and should never need to be called directly.
56
+ # @private
57
+ def flag_details(rank)
58
+ {
59
+ style: flag_style(rank),
60
+ color: flag_color(rank),
61
+ type: flag_type(rank),
62
+ level: flag_level(rank),
63
+ count: flag_count(rank)
64
+ }
65
+ end
73
66
 
74
- # Gets size key for saving PNG images.
75
- #
76
- # This is used USPSFlags::Generate, and should never need to be called directly.
77
- # @private
78
- def size_and_key(size:, flag:)
79
- return [size, size] unless size == 'thumb'
67
+ # Image sizes for generated PNG images.
68
+ #
69
+ # This is used USPSFlags::Generate, and should never need to be called directly.
70
+ # @private
71
+ def png_sizes
72
+ { 1500 => 'H', 1000 => 'K', 500 => 'D', 'thumb' => 'T' }
73
+ end
80
74
 
81
- size = case flag
82
- when 'ENSIGN'
83
- 200
84
- when 'US'
85
- 300
86
- else
87
- 150
75
+ # Gets size key for saving PNG images.
76
+ #
77
+ # This is used USPSFlags::Generate, and should never need to be called directly.
78
+ # @private
79
+ def size_and_key(size:, flag:)
80
+ return [size, size] unless size == 'thumb'
81
+
82
+ size = case flag
83
+ when 'ENSIGN'
84
+ 200
85
+ when 'US'
86
+ 300
87
+ else
88
+ 150
89
+ end
90
+
91
+ [size, 'thumb']
88
92
  end
89
93
 
90
- [size, 'thumb']
91
- end
94
+ # Prints message(s) to the console and logs them.
95
+ #
96
+ # This should never need to be called directly.
97
+ # @private
98
+ def log(*messages)
99
+ ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
100
+ outputs = [STDOUT]
92
101
 
93
- # Prints message(s) to the console and logs them.
94
- #
95
- # This should never need to be called directly.
96
- # @private
97
- def log(*messages)
98
- ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
99
- outputs = [STDOUT]
102
+ log_file = File.open("#{USPSFlags.configuration.log_path}/flag.log", 'a')
103
+ outputs << log_file
100
104
 
101
- log_file = File.open("#{USPSFlags.configuration.log_path}/flag.log", 'a')
102
- outputs << log_file
105
+ messages.each do |message|
106
+ outputs.each { |f| f.write(message) }
107
+ end
103
108
 
104
- messages.each do |message|
105
- outputs.each { |f| f.write(message) }
109
+ messages
110
+ ensure
111
+ log_file.close if log_file.is_a?(File)
106
112
  end
107
113
 
108
- messages
109
- ensure
110
- log_file.close if log_file.is_a?(File)
111
- end
112
-
113
- # Ensures the directory for the specified path exists.
114
- #
115
- # This should never need to be called directly.
116
- # @private
117
- def ensure_dir_for_file(path)
118
- return false if path.nil? || path.empty? || !path.scan('/')
114
+ # Ensures the directory for the specified path exists.
115
+ #
116
+ # This should never need to be called directly.
117
+ # @private
118
+ def ensure_dir_for_file(path)
119
+ return false if path.nil? || path.empty? || !path.scan('/')
119
120
 
120
- dirs = path.split('/')
121
- dirs.pop
122
- ::FileUtils.mkdir_p(dirs.join('/')).first
123
- end
121
+ dirs = path.split('/')
122
+ dirs.pop
123
+ ::FileUtils.mkdir_p(dirs.join('/')).first
124
+ end
124
125
 
125
- # Prints output to the console or saves to a file, then returns the generated data.
126
- #
127
- # This should never need to be called directly.
128
- # @private
129
- def output(svg, outfile: nil)
130
- if outfile.nil?
131
- puts svg, "\n"
132
- elsif outfile != ''
133
- ensure_dir_for_file(outfile)
134
- f = ::File.new(outfile, 'w+')
135
- f.write(svg)
136
- f.close
137
- end
138
- svg
139
- end
126
+ # Prints output to the console or saves to a file, then returns the generated data.
127
+ #
128
+ # This should never need to be called directly.
129
+ # @private
130
+ def output(svg, outfile: nil)
131
+ if outfile.nil?
132
+ puts svg, "\n"
133
+ elsif outfile != ''
134
+ ensure_dir_for_file(outfile)
135
+ f = ::File.new(outfile, 'w+')
136
+ f.write(svg)
137
+ f.close
138
+ end
139
+ svg
140
+ end
140
141
 
141
- private
142
+ private
142
143
 
143
- def resize_convert(size, png_file, output_file_name)
144
- MiniMagick::Tool::Convert.new do |convert|
145
- convert << '-background' << 'none'
146
- convert << '-format' << 'png'
147
- convert << '-resize' << "#{size}"
148
- convert << png_file
149
- convert << output_file_name
144
+ def resize_convert(size, png_file, output_file_name)
145
+ MiniMagick::Tool::Convert.new do |convert|
146
+ convert << '-background' << 'none'
147
+ convert << '-format' << 'png'
148
+ convert << '-resize' << size.to_s
149
+ convert << png_file
150
+ convert << output_file_name
151
+ end
150
152
  end
151
- end
152
153
 
153
- def flag_style(rank)
154
- return :past if valid_flags(:past).include?(rank)
155
- return :swallowtail if valid_flags(:swallowtail).include?(rank)
154
+ def flag_style(rank)
155
+ return :past if valid_flags(:past).include?(rank)
156
+ return :swallowtail if valid_flags(:swallowtail).include?(rank)
156
157
 
157
- :regular
158
- end
158
+ :regular
159
+ end
159
160
 
160
- def flag_color(rank)
161
- return :blue if valid_flags(:command).include?(rank)
162
- return :red if valid_flags(:bridge).include?(rank)
161
+ def flag_color(rank)
162
+ return :blue if valid_flags(:command).include?(rank)
163
+ return :red if valid_flags(:bridge).include?(rank)
163
164
 
164
- :white
165
- end
165
+ :white
166
+ end
166
167
 
167
- def flag_level(rank)
168
- return :n if rank.match? /N.*/
169
- return :d if rank.match? /D.*/
170
- return :s if rank == 'FLT'
171
- end
168
+ def flag_level(rank)
169
+ return :n if rank.match?(/N.*/)
170
+ return :d if rank.match?(/D.*/)
171
+ return :s if rank == 'FLT'
172
+ end
172
173
 
173
- def flag_count(rank)
174
- return 3 if valid_flags(:command).include?(rank)
175
- return 2 if valid_flags(:bridge).include?(rank)
174
+ def flag_count(rank)
175
+ return 3 if valid_flags(:command).include?(rank)
176
+ return 2 if valid_flags(:bridge).include?(rank)
176
177
 
177
- 1
178
- end
178
+ 1
179
+ end
180
+
181
+ def flag_type(rank)
182
+ specifics = { 'PORTCAP' => :pc, 'FLEETCAP' => :fc, 'STFC' => :stf }
183
+ return specifics[rank] if specifics.key?(rank)
184
+ return :a if rank.match?(/.AIDE/)
185
+ return :f if rank.match?(/.?FLT/)
179
186
 
180
- def flag_type(rank) # Complexity
181
- specifics = { 'PORTCAP' => :pc, 'FLEETCAP' => :fc, 'STFC' => :stf }
182
- if specifics.keys.include?(rank)
183
- specifics[rank]
184
- elsif rank.match? /.AIDE/
185
- :a
186
- elsif rank.match? /.?FLT/
187
- :f
188
- else
189
187
  get_line_flag_level(rank)
190
188
  end
191
- end
192
189
 
193
- def get_line_flag_level(rank)
194
- return :s if valid_flags(:squadron).include?(rank)
195
- return :d if valid_flags(:district).include?(rank)
196
- return :n if valid_flags(:national).include?(rank)
190
+ def get_line_flag_level(rank)
191
+ return :s if valid_flags(:squadron).include?(rank)
192
+ return :d if valid_flags(:district).include?(rank)
193
+ return :n if valid_flags(:national).include?(rank)
194
+ end
197
195
  end
198
196
  end
199
197
  end