lib/usps_flags/helpers.rb in usps_flags-0.3.1 vs lib/usps_flags/helpers.rb in usps_flags-0.3.2

- old
+ new

@@ -12,56 +12,12 @@ # @option type [Symbol] :national National-level officer flags # @option type [Symbol] :special Special flags # @option type [Symbol] :us US flag # @return [Array] Valid options for flag generation (based on the provided type). def valid_flags(type = :all) - squadron_past = %w[PLTC PC] - squadron_elected = %w[1LT LTC CDR] - squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT] - district_past = %w[PDLTC PDC] - district_elected = %w[D1LT DLTC DC] - district_swallowtail = %w[DLT DAIDE DFLT] - national_past = %w[PSTFC PRC PVC PCC] - national_elected = %w[NAIDE NFLT STFC RC VC CC] - special = %w[CRUISE OIC ENSIGN WHEEL] - us = %w[US] - - squadron = squadron_past + squadron_elected + squadron_swallowtail - district = district_past + district_elected + district_swallowtail - national = national_past + national_elected - past = squadron_past + district_past + national_past - - case type - when :all - squadron + district + national + special + us - when :officer - squadron + district + national - when :insignia - squadron + district + national - past - when :squadron - squadron - when :district - district - when :national - national - when :special - special - when :us - us - when :past - past - when :swallowtail - past + squadron_swallowtail + district_swallowtail - when :bridge - squadron_elected.last(2) + squadron_past.last(2) + - district_elected.last(2) + district_past.last(2) + - national_elected.last(2) + national_past.last(2) - when :command - [squadron_elected.last, squadron_past.last, - district_elected.last, district_past.last, - national_elected.last, national_past.last] - end + load_valid_flags + valid_flags_for(type) end # Gets the maximum length among valid flags. # # This is used USPSFlags::Generate, and should never need to be called directly. @@ -163,10 +119,54 @@ end svg end private + def load_valid_flags + @squadron_past = %w[PLTC PC] + @squadron_elected = %w[1LT LTC CDR] + @squadron_swallowtail = %w[PORTCAP FLEETCAP LT FLT] + @district_past = %w[PDLTC PDC] + @district_elected = %w[D1LT DLTC DC] + @district_swallowtail = %w[DLT DAIDE DFLT] + @national_past = %w[PSTFC PRC PVC PCC] + @national_elected = %w[NAIDE NFLT STFC RC VC CC] + @special = %w[CRUISE OIC ENSIGN WHEEL] + @us = %w[US] + + @past = @squadron_past + @district_past + @national_past + @squadron = @squadron_past + @squadron_elected + @squadron_swallowtail + @district = @district_past + @district_elected + @district_swallowtail + @national = @national_past + @national_elected + @officer = @squadron + @district + @national + end + + def valid_flags_for(type) + { + special: @special, + us: @us, + + squadron: @squadron, + district: @district, + national: @national, + past: @past, + + all: @officer + @special + @us, + officer: @officer, + insignia: @officer - @past, + swallowtail: @past + @squadron_swallowtail + @district_swallowtail, + + bridge: @squadron_elected.last(2) + @squadron_past.last(2) + + @district_elected.last(2) + @district_past.last(2) + + @national_elected.last(2) + @national_past.last(2), + + command: [@squadron_elected.last, @squadron_past.last, + @district_elected.last, @district_past.last, + @national_elected.last, @national_past.last] + }[type] + end + def flag_style(rank) if valid_flags(:past).include?(rank) :past elsif valid_flags(:swallowtail).include?(rank) :swallowtail @@ -186,22 +186,16 @@ :white end end def flag_level(rank) - if rank == "DAIDE" - :d - elsif rank == "NAIDE" + if rank.match /N.*/ :n + elsif rank.match /D.*/ + :d elsif rank == "FLT" :s - elsif rank == "DFLT" - :d - elsif rank == "NFLT" - :n - else - nil end end def flag_count(rank) if valid_flags(:command).include?(rank) @@ -216,22 +210,22 @@ def flag_type(rank) if rank == "PORTCAP" :pc elsif rank == "FLEETCAP" :fc - elsif rank == "DAIDE" - :a - elsif rank == "NAIDE" - :a - elsif rank == "FLT" - :f - elsif rank == "DFLT" - :f - elsif rank == "NFLT" - :f elsif rank == "STFC" :stf - elsif valid_flags(:squadron).include?(rank) + elsif rank.match /.AIDE/ + :a + elsif rank.match /.?FLT/ + :f + else + get_line_flag_level(rank) + end + end + + def get_line_flag_level(rank) + if valid_flags(:squadron).include?(rank) :s elsif valid_flags(:district).include?(rank) :d elsif valid_flags(:national).include?(rank) :n