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
Class Attribute Summary collapse
-
.configuration ⇒ Object
Configuration accessor.
Instance Attribute Summary collapse
-
#field ⇒ Object
Constructor accessors.
-
#png_file ⇒ Object
Constructor accessors.
-
#scale ⇒ Object
Constructor accessors.
-
#svg_file ⇒ Object
Constructor accessors.
-
#trim ⇒ Object
Constructor accessors.
-
#type ⇒ Object
Constructor accessors.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Object
Configuration constructor.
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.
101 102 103 104 105 106 107 108 109 |
# File 'lib/usps_flags.rb', line 101 def initialize @type = nil @svg_file = nil @png_file = nil @scale = nil @field = nil @trim = nil yield self if block_given? end |
Class Attribute Details
.configuration ⇒ Object
Configuration accessor.
34 35 36 |
# File 'lib/usps_flags.rb', line 34 def configuration @configuration end |
Instance Attribute Details
#field ⇒ Object
Constructor accessors.
119 120 121 |
# File 'lib/usps_flags.rb', line 119 def field @field end |
#png_file ⇒ Object
Constructor accessors.
119 120 121 |
# File 'lib/usps_flags.rb', line 119 def png_file @png_file end |
#scale ⇒ Object
Constructor accessors.
119 120 121 |
# File 'lib/usps_flags.rb', line 119 def scale @scale end |
#svg_file ⇒ Object
Constructor accessors.
119 120 121 |
# File 'lib/usps_flags.rb', line 119 def svg_file @svg_file end |
#trim ⇒ Object
Constructor accessors.
119 120 121 |
# File 'lib/usps_flags.rb', line 119 def trim @trim end |
#type ⇒ Object
Constructor accessors.
119 120 121 |
# File 'lib/usps_flags.rb', line 119 def type @type end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
Configuration constructor.
39 40 41 42 43 |
# File 'lib/usps_flags.rb', line 39 def self.configure yield(configuration) if block_given? self.ensure_directories @configuration end |
Instance Method Details
#png ⇒ String
Generates the constructed file as PNG.
Requires the constructor to have a value for png_file.
134 135 136 137 138 139 140 141 142 |
# File 'lib/usps_flags.rb', line 134 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 |
#svg ⇒ String
Generates the constructed file as SVG.
124 125 126 127 |
# File 'lib/usps_flags.rb', line 124 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 |