Class: LabelFactory::Layout::Length
- Inherits:
-
Object
- Object
- LabelFactory::Layout::Length
- Defined in:
- lib/label_factory/layout/length.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
Returns the value of attribute number.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#as_pts ⇒ Object
Return the numeric portion as a Points.
-
#initialize(value) ⇒ Length
constructor
A new instance of Length.
Constructor Details
#initialize(value) ⇒ Length
Returns a new instance of Length.
7 8 9 10 11 |
# File 'lib/label_factory/layout/length.rb', line 7 def initialize(value) @value = value @number = value.match(/[\d\.]*/)[0].to_f @unit = value.delete("#{number}").strip end |
Instance Attribute Details
#number ⇒ Object
Returns the value of attribute number.
5 6 7 |
# File 'lib/label_factory/layout/length.rb', line 5 def number @number end |
#unit ⇒ Object
Returns the value of attribute unit.
5 6 7 |
# File 'lib/label_factory/layout/length.rb', line 5 def unit @unit end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/label_factory/layout/length.rb', line 5 def value @value end |
Instance Method Details
#as_pts ⇒ Object
Return the numeric portion as a Points
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/label_factory/layout/length.rb', line 14 def as_pts if @unit =~ /pt/ return @number elsif @unit =~ /in/ return @number * 72 #72.270 elsif @unit =~ /mm/ return @number * 2.83464566929134 elsif @unit =~ /cm/ return @number * 28.3464566929134 elsif @unit =~ /pc/ return 1.0 * @number / 12 elsif @unit == '' return @number else raise "Unit #{unit} unknown" end end |