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.
35 36 37 38 39 40 41 42 43 |
# File 'lib/usps_flags.rb', line 35 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).
103 104 105 106 107 108 109 110 |
# File 'lib/usps_flags.rb', line 103 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.
138 139 140 141 142 143 144 145 |
# File 'lib/usps_flags.rb', line 138 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.
75 76 77 78 79 80 81 82 |
# File 'lib/usps_flags.rb', line 75 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.
90 91 92 93 94 95 96 97 |
# File 'lib/usps_flags.rb', line 90 def scale(num = nil) if num.nil? @scale else @scale = num self end end |
#svg ⇒ String
Generates the constructed file as SVG.
128 129 130 131 |
# File 'lib/usps_flags.rb', line 128 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.
62 63 64 65 66 67 68 69 |
# File 'lib/usps_flags.rb', line 62 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.
116 117 118 119 120 121 122 123 |
# File 'lib/usps_flags.rb', line 116 def trim(bool = nil) if bool.nil? @trim else @trim = bool self end end |
#type(string = nil) ⇒ String
Constructor accessor for the flag type.
49 50 51 52 53 54 55 56 |
# File 'lib/usps_flags.rb', line 49 def type(string = nil) if string.nil? @type else @type = string self end end |