lib/usps_flags/generate/flag.rb in usps_flags-0.3.4 vs lib/usps_flags/generate/flag.rb in usps_flags-0.3.5
- old
+ new
@@ -3,27 +3,21 @@
# These methods should never need to be called directly.
# @private
class USPSFlags::Generate::Flag
class << self
def officer(rank: nil, width: USPSFlags::Config::BASE_FLY, outfile: nil, scale: nil, field: true)
- raise "Error: No rank specified." if rank.nil?
+ raise ArgumentError, "No rank specified." if rank.nil?
@rank = rank.to_s.upcase
@field = field
svg = ""
svg << USPSFlags::Core.headers(scale: scale, title: @rank)
-
modify_rank_for_insignia
@flag_details = USPSFlags::Helpers.flag_details(@rank)
@trident_color = @field ? :white : @flag_details[:color]
+ svg << officer_flag_body
- svg << USPSFlags::Core.field(style: @flag_details[:style], color: @flag_details[:color]) if @field
- svg << "<g transform=\"translate(-150, 400)\"><g transform=\"scale(0.58333)\">" if @flag_details[:style] == :past
- svg << get_officer_flag
- svg << "</g></g>" if @flag_details[:style] == :past
- svg << USPSFlags::Core.footer
-
USPSFlags::Helpers.output(svg, outfile: outfile)
end
def special(type, level:, field: true)
# Paths were designed for a base fly of 3000 pixels, but the base was changed for more useful fractions.
@@ -95,28 +89,62 @@
USPSFlags::Helpers.output(svg, outfile: outfile)
end
private
def get_officer_flag
- if @flag_details[:type] == :n && @flag_details[:count] == 3
+ if cc?
USPSFlags::Core::Tridents.cc(@flag_details[:type], trident_color: @trident_color)
- elsif @flag_details[:type] == :n && @flag_details[:count] == 2
+ elsif vc?
USPSFlags::Core::Tridents.vc(@flag_details[:type], trident_color: @trident_color)
- elsif [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 3
+ elsif cdr_or_dc?
USPSFlags::Core::Tridents.three(@flag_details[:type], trident_color: @trident_color, field_color: @flag_details[:color])
- elsif [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 2
+ elsif ltc_or_dltc?
USPSFlags::Core::Tridents.two(@flag_details[:type], trident_color: @trident_color, field_color: @flag_details[:color])
- elsif [:s, :d, :stf, :n].include?(@flag_details[:type]) && %w[LT DLT].include?(@rank)
+ elsif lt_or_dlt?
USPSFlags::Core::Tridents.offset(@flag_details[:type], field_color: @flag_details[:color], field: @field)
- elsif [:a, :f, :fc, :pc].include?(@flag_details[:type])
+ elsif special_officer?
special(@flag_details[:type], level: @flag_details[:level], field: @field)
else
USPSFlags::Core.trident(@flag_details[:type], field_color: @flag_details[:color])
end
end
+ def officer_flag_body
+ svg = ""
+ svg << USPSFlags::Core.field(style: @flag_details[:style], color: @flag_details[:color]) if @field
+ svg << "<g transform=\"translate(-150, 400)\"><g transform=\"scale(0.58333)\">" if @flag_details[:style] == :past
+ svg << get_officer_flag
+ svg << "</g></g>" if @flag_details[:style] == :past
+ svg << USPSFlags::Core.footer
+ svg
+ end
+
def modify_rank_for_insignia
@rank.slice!(0) if !@field && USPSFlags::Helpers.valid_flags(:past).include?(@rank)
@rank = "CDR" if @rank == "C"
+ end
+
+ def cc?
+ @flag_details[:type] == :n && @flag_details[:count] == 3
+ end
+
+ def vc?
+ @flag_details[:type] == :n && @flag_details[:count] == 2
+ end
+
+ def cdr_or_dc?
+ [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 3
+ end
+
+ def ltc_or_dltc?
+ [:s, :d].include?(@flag_details[:type]) && @flag_details[:count] == 2
+ end
+
+ def lt_or_dlt?
+ %w[LT DLT].include?(@rank)
+ end
+
+ def special_officer?
+ [:a, :f, :fc, :pc].include?(@flag_details[:type])
end
end
end