Class: USPSFlags
- Inherits:
-
Object
- Object
- USPSFlags
- Defined in:
- lib/usps_flags.rb
Overview
Base class for the namespace. Provides a constructor DSL.
Defined Under Namespace
Classes: Config, Generate, Helpers
Instance Method Summary collapse
-
#field(bool = nil) ⇒ Boolean
Constructor accessor for whether to generate the flag field (including any border).
-
#initialize(&block) ⇒ USPSFlags
constructor
Constructor for individual flags.
-
#png ⇒ String
Generates the constructed file as PNG.
-
#png_file(string = nil) ⇒ String
Constructor accessor for the PNG file output path.
-
#scale(num = nil) ⇒ Integer, Float
Constructor accessor for the image scale divisor factor.
-
#svg ⇒ String
Generates the constructed file as SVG.
-
#svg_file(string = nil) ⇒ String
Constructor accessor for the SVG file output path.
-
#trim(bool = nil) ⇒ String
Constructor accessor for whether to trim the generated PNG file of excess transparency.
-
#type(string = nil) ⇒ String
Constructor accessor for the flag type.
Constructor Details
#initialize(&block) ⇒ USPSFlags
Constructor for individual flags.
29 30 31 32 33 34 35 36 37 |
# File 'lib/usps_flags.rb', line 29 def initialize(&block) @type = nil @svg_file = nil @png_file = nil @scale = nil @field = nil @trim = nil instance_eval(&block) if block_given? end |
Instance Method Details
#field(bool = nil) ⇒ Boolean
Constructor accessor for whether to generate the flag field (including any border).
97 98 99 100 101 102 103 104 |
# File 'lib/usps_flags.rb', line 97 def field(bool = nil) if bool.nil? @field else @field = bool self end end |
#png ⇒ String
Generates the constructed file as PNG.
Requires the constructor to have a value for png_file.
132 133 134 135 136 137 138 139 |
# File 'lib/usps_flags.rb', line 132 def png raise "Error: png_file must be set." if self.png_file.nil? svg_file_storage = self.svg_file self.svg_file "" USPSFlags::Generate.png(self.svg, outfile: self.png_file, trim: self.trim) self.svg_file svg_file_storage self.png_file end |
#png_file(string = nil) ⇒ String
Constructor accessor for the PNG file output path.
69 70 71 72 73 74 75 76 |
# File 'lib/usps_flags.rb', line 69 def png_file(string = nil) if string.nil? @png_file else @png_file = string self end end |
#scale(num = nil) ⇒ Integer, Float
Constructor accessor for the image scale divisor factor.
Available options are Float between 0 and 1, or Integer above 1.
84 85 86 87 88 89 90 91 |
# File 'lib/usps_flags.rb', line 84 def scale(num = nil) if num.nil? @scale else @scale = num self end end |
#svg ⇒ String
Generates the constructed file as SVG.
122 123 124 125 |
# File 'lib/usps_flags.rb', line 122 def svg svg = USPSFlags::Generate.get(self.type, outfile: self.svg_file, scale: self.scale, field: self.field) (self.svg_file.nil? || self.svg_file == "") ? svg : self.svg_file end |
#svg_file(string = nil) ⇒ String
Constructor accessor for the SVG file output path.
56 57 58 59 60 61 62 63 |
# File 'lib/usps_flags.rb', line 56 def svg_file(string = nil) if string.nil? @svg_file else @svg_file = string self end end |
#trim(bool = nil) ⇒ String
Constructor accessor for whether to trim the generated PNG file of excess transparency.
110 111 112 113 114 115 116 117 |
# File 'lib/usps_flags.rb', line 110 def trim(bool = nil) if bool.nil? @trim else @trim = bool self end end |
#type(string = nil) ⇒ String
Constructor accessor for the flag type.
43 44 45 46 47 48 49 50 |
# File 'lib/usps_flags.rb', line 43 def type(string = nil) if string.nil? @type else @type = string self end end |