class Rulerr::Conversion

Constants

DEFAULT_UNIT
FACTOR_BY_UNIT

Attributes

number[R]
unit[R]

Public Class Methods

new(value) click to toggle source
# File lib/rulerr.rb, line 17
def initialize(value)
  @number = value.to_f
  @unit   = (
    value.match(/[a-z]{1,2}$/i).to_a[0] ||
    DEFAULT_UNIT
  ).downcase
end

Public Instance Methods

to_cm() click to toggle source
# File lib/rulerr.rb, line 30
def to_cm
  to_m * FACTOR_BY_UNIT['cm']
end
to_in() click to toggle source
# File lib/rulerr.rb, line 42
def to_in
  to_m * FACTOR_BY_UNIT['in']
end
to_m() click to toggle source
# File lib/rulerr.rb, line 34
def to_m
  number / FACTOR_BY_UNIT[unit]
end
to_mm() click to toggle source

eg: “23.45cm” => “234.5mm”

# File lib/rulerr.rb, line 26
def to_mm
  to_m * FACTOR_BY_UNIT['mm']
end
to_pt() click to toggle source
# File lib/rulerr.rb, line 46
def to_pt
  to_m * FACTOR_BY_UNIT['pt']
end
to_px() click to toggle source
# File lib/rulerr.rb, line 38
def to_px
  to_m * FACTOR_BY_UNIT['px']
end