Class: Pdf::Label::Length
- Inherits:
-
Object
- Object
- Pdf::Label::Length
- Defined in:
- lib/pdf/label/length_node.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.
8 9 10 11 12 |
# File 'lib/pdf/label/length_node.rb', line 8 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.
6 7 8 |
# File 'lib/pdf/label/length_node.rb', line 6 def number @number end |
#unit ⇒ Object
Returns the value of attribute unit.
6 7 8 |
# File 'lib/pdf/label/length_node.rb', line 6 def unit @unit end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/pdf/label/length_node.rb', line 6 def value @value end |
Instance Method Details
#as_pts ⇒ Object
Return the numeric portion as a Points
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pdf/label/length_node.rb', line 15 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 |