Class: USPSFlags::Generate::Flag

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

Class Method Summary collapse

Class Method Details

.ensign(outfile: nil, scale: nil) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/usps_flags/generate/flag.rb', line 49

def ensign(outfile: nil, scale: nil)
  svg = USPSFlags::Core.headers(scale: scale, title: 'USPS Ensign')
  svg << USPSFlags::Core.ensign
  svg << USPSFlags::Core.footer

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

.officer(rank: nil, outfile: nil, scale: nil, field: true) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/usps_flags/generate/flag.rb', line 11

def officer(rank: nil, outfile: nil, scale: nil, field: true)
  raise ArgumentError, 'No rank specified.' if rank.nil?

  @rank = rank.to_s.upcase
  @field = field

  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(@flag_details[:style])

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

.pennant(type: 'CRUISE', outfile: nil, scale: nil) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/usps_flags/generate/flag.rb', line 39

def pennant(type: 'CRUISE', outfile: nil, scale: nil)
  type = type.upcase
  title = { 'CRUISE' => 'Cruise Pennant', 'OIC' => 'Officer-in-Charge Pennant' }[type]
  svg = USPSFlags::Core.headers(pennant: true, scale: scale, title: title)
  svg << USPSFlags::Core.pennant(type)
  svg << USPSFlags::Core.footer

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

.special(type, level:, field: true) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/usps_flags/generate/flag.rb', line 26

def special(type, level:, field: true)
  translate = (type == :f && level == :n) || !field
  # Paths were designed for a base fly of 3000 pixels, but the base was changed for more useful fractions.
  svg = +''
  svg << "<g transform=\"translate(#{USPSFlags::Config::BASE_FLY / 10})\">" if translate
  svg << "<g transform=\"scale(#{Rational(USPSFlags::Config::BASE_FLY, 3000).to_f})\">"
  svg << special_icon(type, level)
  svg << '</g>'
  svg << '</g>' if translate

  svg
end

.us(outfile: nil, scale: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/usps_flags/generate/flag.rb', line 67

def us(outfile: nil, scale: nil)
  base_hoist = 2000.to_f
  hoist = scale.nil? ? base_hoist : (base_hoist / scale)
  fly = hoist * 1.91
  svg = USPSFlags::Core.headers(width: fly, height: hoist, scale: scale, title: 'US Ensign')
  svg << USPSFlags::Core.us
  svg << USPSFlags::Core.footer

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

.wheel(outfile: nil, scale: nil) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/usps_flags/generate/flag.rb', line 57

def wheel(outfile: nil, scale: nil)
  width = 4327.4667
  height = 4286.9333
  svg = USPSFlags::Core.headers(width: width, height: height, scale: scale, title: 'USPS Ensign Wheel')
  svg << USPSFlags::Core.wheel
  svg << USPSFlags::Core.footer

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