Class: Length

Inherits:
Object
  • Object
show all
Defined in:
lib/length_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Length

Returns a new instance of Length.



5
6
7
8
9
# File 'lib/length_node.rb', line 5

def initialize(value)
  @value = value
  @number = value.match(/[\d\.]*/)[0].to_f
  @unit = value.delete("#{number}").strip
end

Instance Attribute Details

#numberObject

Returns the value of attribute number.



3
4
5
# File 'lib/length_node.rb', line 3

def number
  @number
end

#unitObject

Returns the value of attribute unit.



3
4
5
# File 'lib/length_node.rb', line 3

def unit
  @unit
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/length_node.rb', line 3

def value
  @value
end

Instance Method Details

#as_ptsObject

Return the numeric portion as a Points



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/length_node.rb', line 12

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