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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/usps_flags.rb', line 45 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).
85 86 87 |
# File 'lib/usps_flags.rb', line 85 def field @field end |
#png_file ⇒ String
Constructor accessor for the PNG file output path.
71 72 73 |
# File 'lib/usps_flags.rb', line 71 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.
79 80 81 |
# File 'lib/usps_flags.rb', line 79 def scale @scale end |
#svg_file ⇒ String
Constructor accessor for the SVG file output path.
65 66 67 |
# File 'lib/usps_flags.rb', line 65 def svg_file @svg_file end |
#trim ⇒ String
Constructor accessor for whether to trim the generated PNG file of excess transparency.
91 92 93 |
# File 'lib/usps_flags.rb', line 91 def trim @trim end |
#type ⇒ String
Constructor accessor for the flag type.
59 60 61 |
# File 'lib/usps_flags.rb', line 59 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.
106 107 108 109 110 111 112 113 |
# File 'lib/usps_flags.rb', line 106 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 |