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 Attribute Summary collapse
-
#field ⇒ Boolean
Constructor accessor for whether to generate the flag field (including any border).
-
#png_file ⇒ String
Constructor accessor for the PNG file output path.
-
#scale ⇒ Integer, Float
Constructor accessor for the image scale divisor factor.
-
#svg_file ⇒ String
Constructor accessor for the SVG file output path.
-
#trim ⇒ String
Constructor accessor for whether to trim the generated PNG file of excess transparency.
-
#type ⇒ String
Constructor accessor for the flag type.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ USPSFlags
constructor
Constructor for individual flags.
-
#png ⇒ String
Generates the constructed file as PNG.
-
#svg ⇒ String
Generates the constructed file as SVG.
Constructor Details
#initialize {|_self| ... } ⇒ USPSFlags
Constructor for individual flags.
46 47 48 49 50 51 52 53 54 |
# File 'lib/usps_flags.rb', line 46 def initialize @type = nil @svg_file = nil @png_file = nil @scale = nil @field = nil @trim = nil yield self if block_given? end |
Instance Attribute Details
#field ⇒ Boolean
Constructor accessor for whether to generate the flag field (including any border).
86 87 88 |
# File 'lib/usps_flags.rb', line 86 def field @field end |
#png_file ⇒ String
Constructor accessor for the PNG file output path.
72 73 74 |
# File 'lib/usps_flags.rb', line 72 def png_file @png_file end |
#scale ⇒ Integer, Float
Constructor accessor for the image scale divisor factor.
Available options are Float between 0 and 1, or Integer above 1.
80 81 82 |
# File 'lib/usps_flags.rb', line 80 def scale @scale end |
#svg_file ⇒ String
Constructor accessor for the SVG file output path.
66 67 68 |
# File 'lib/usps_flags.rb', line 66 def svg_file @svg_file end |
#trim ⇒ String
Constructor accessor for whether to trim the generated PNG file of excess transparency.
92 93 94 |
# File 'lib/usps_flags.rb', line 92 def trim @trim end |
#type ⇒ String
Constructor accessor for the flag type.
60 61 62 |
# File 'lib/usps_flags.rb', line 60 def type @type end |
Instance Method Details
#png ⇒ String
Generates the constructed file as PNG.
Requires the constructor to have a value for png_file.
107 108 109 110 111 112 113 114 |
# File 'lib/usps_flags.rb', line 107 def png raise USPSFlags::Errors::PNGGenerationError, "A path must be set with png_file." 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 |