Sha256: 884773c18a027f95b75181d9ae1f52b8f73d0b67add4d3d46805e3ca4ec458af

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require 'usps_flags'
require 'usps_flags/burgees/config'
require 'usps_flags/burgees/errors'

class USPSFlags::Burgees
  require 'usps_flags/burgees/builtins'
  require 'usps_flags/burgees/customs'

  class << self
    def available
      USPSFlags::Burgees::Builtins.available + USPSFlags::Burgees::Customs.available
    end

    def get(burgee, outfile: nil)
      raise USPSFlags::Errors::UnknownBurgee unless available.include?(burgee)

      # Configuration values may be editable
      @width = 3000
      @height = 2000
      @view_width = 3000
      @view_height = 2000
      @title = title(burgee)

      @generated_at = Time.now.strftime("%Y%m%d.%H%S%z")

      svg = <<~SVG
        #{USPSFlags::Core.headers}
        #{core(burgee)}
        #{USPSFlags::Core.footer}
      SVG

      USPSFlags::Helpers.output(svg, outfile: outfile)
    end

    private
    def core(burgee)
      if custom?(burgee)
        USPSFlags::Burgees::Customs.get(burgee)
      elsif builtin?(burgee)
        USPSFlags::Burgees::Builtins.get(burgee)
      end
    end

    def custom?(burgee)
      USPSFlags::Burgees::Customs.available.include?(burgee)
    end

    def builtin?(burgee)
      USPSFlags::Burgees::Builtins.available.include?(burgee)
    end

    def title(burgee)
      burgee_string = burgee.to_s
      burgee_title = if burgee.match /_/
        burgee_string.split("_").map { |word| word.capitalize } + " Burgee"
      else
        "#{burgee_string} Burgee"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
usps_flags-burgees-0.0.3 lib/usps_flags/burgees.rb
usps_flags-burgees-0.0.2 lib/usps_flags/burgees.rb