Class: LabelFactory::Layout::Length

Inherits:
Object
  • Object
show all
Defined in:
lib/label_factory/layout/length.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#numberObject

Returns the value of attribute number.



5
6
7
# File 'lib/label_factory/layout/length.rb', line 5

def number
  @number
end

#unitObject

Returns the value of attribute unit.



5
6
7
# File 'lib/label_factory/layout/length.rb', line 5

def unit
  @unit
end

#valueObject

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_ptsObject

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