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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/usps_flags.rb', line 45 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).
113 114 115 116 117 118 119 120 |
# File 'lib/usps_flags.rb', line 113 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.
148 149 150 151 152 153 154 155 |
# File 'lib/usps_flags.rb', line 148 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.
85 86 87 88 89 90 91 92 |
# File 'lib/usps_flags.rb', line 85 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.
100 101 102 103 104 105 106 107 |
# File 'lib/usps_flags.rb', line 100 def scale(num = nil) if num.nil? @scale else @scale = num self end end |
#svg ⇒ String
Generates the constructed file as SVG.
138 139 140 141 |
# File 'lib/usps_flags.rb', line 138 def svg svg = USPSFlags::Generate.svg(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.
72 73 74 75 76 77 78 79 |
# File 'lib/usps_flags.rb', line 72 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.
126 127 128 129 130 131 132 133 |
# File 'lib/usps_flags.rb', line 126 def trim(bool = nil) if bool.nil? @trim else @trim = bool self end end |
#type(string = nil) ⇒ String
Constructor accessor for the flag type.
59 60 61 62 63 64 65 66 |
# File 'lib/usps_flags.rb', line 59 def type(string = nil) if string.nil? @type else @type = string self end end |