Class: USPSFlags::Burgees

Inherits:
Object
  • Object
show all
Defined in:
lib/usps_flags/burgees.rb

Overview

Main class for generating burgees.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Burgees

Constructor for generating burgees.

Examples:

Generate Birmingham’s burgee

burgee = USPSFlags::Burgee.new do |b|
  b.type = :birmingham
  b.outfile = "/path/to/svg/output.svg"
end

burgee.svg #=> Generates SVG file at "/path/to/svg/output.svg"

Yields:

  • (_self)

Yield Parameters:



24
25
26
27
28
29
30
31
32
33
# File 'lib/usps_flags/burgees.rb', line 24

def initialize
  @squadron = nil
  @outfile = nil
  # @width = 3000
  # @height = 2000
  @title = nil
  @generated_at = Time.now.strftime("%Y%m%d.%H%S%z")
  yield self if block_given?
  @title ||= title(@squadron)
end

Instance Attribute Details

#outfileObject

Returns the value of attribute outfile.



36
37
38
# File 'lib/usps_flags/burgees.rb', line 36

def outfile
  @outfile
end

#squadronObject

Returns the value of attribute squadron.



35
36
37
# File 'lib/usps_flags/burgees.rb', line 35

def squadron
  @squadron
end

#title=(value) ⇒ Object

attr_accessor :width attr_accessor :height



39
40
41
# File 'lib/usps_flags/burgees.rb', line 39

def title=(value)
  @title = value
end

Class Method Details

.availableObject

List of available burgees.



11
12
13
# File 'lib/usps_flags/burgees.rb', line 11

def self.available
  (USPSFlags::Burgees::Builtins.available + USPSFlags::Burgees::Customs.available).uniq
end

Instance Method Details

#svgString

Generates the constructed file as SVG.

Returns:

  • (String)

    Returns the SVG file output path, or the svg data if no path was specified.

Raises:



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/usps_flags/burgees.rb', line 45

def svg
  raise USPSFlags::Errors::UnknownBurgee unless USPSFlags::Burgees.available.include?(@squadron)

  @svg = "    \#{USPSFlags::Core.headers(title: @title)}\n    \#{core(@squadron)}\n    \#{USPSFlags::Core.footer}\n  SVG\n\n  USPSFlags::Helpers.output(@svg, outfile: @outfile)\nend\n"