lib/usps_flags/burgees.rb in usps_flags-burgees-0.0.22 vs lib/usps_flags/burgees.rb in usps_flags-burgees-0.1.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'usps_flags' require 'usps_flags/burgees/config' require 'usps_flags/burgees/errors' # Main class for generating burgees. @@ -26,11 +28,11 @@ @squadron = nil @outfile = nil # @width = 3000 # @height = 2000 @title = nil - @generated_at = Time.now.strftime("%Y%m%d.%H%S%z") + @generated_at = Time.now.strftime('%Y%m%d.%H%S%z') yield self if block_given? @title ||= title(@squadron) end attr_accessor :squadron @@ -45,28 +47,23 @@ # @params crossed Returns the burgee crossed-staves with the Ensign. # @return [String] Returns the SVG file output path, or the svg data if no path was specified. def svg(crossed: false) raise USPSFlags::Errors::UnknownBurgee unless USPSFlags::Burgees.available.include?(@squadron) - if crossed - burgee = crossed(@squadron) - header_opts = { width: 1200, height: 600, scale: 7.25 } - else - burgee = core(@squadron) - header_opts = {} - end + burgee = crossed ? crossed(@squadron) : core(@squadron) + header_opts = crossed ? { width: 1200, height: 600, scale: 7.25 } : {} @svg = <<~SVG #{USPSFlags::Core.headers(header_opts.merge(title: @title))} #{burgee} #{USPSFlags::Core.footer} SVG USPSFlags::Helpers.output(@svg, outfile: @outfile) end - private +private def core(burgee) if custom?(burgee) USPSFlags::Burgees::Customs.get(burgee) elsif builtin?(burgee) @@ -86,11 +83,11 @@ USPSFlags::Burgees::Builtins.available.include?(burgee) end def title(burgee) burgee_string = burgee.to_s - burgee_title = if burgee_string.match(/_/) - burgee_string.gsub("_", " ").split(" ").map { |word| word.capitalize }.join(" ") + " Burgee" + if burgee_string.match?(/_/) + burgee_string.gsub('_', ' ').split(' ').map { |word| word.capitalize }.join(' ') + ' Burgee' else "#{burgee_string.capitalize} Burgee" end end end