Class: String

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

Instance Method Summary collapse

Instance Method Details

#convert_to(other) ⇒ Unit

Parameters:

  • other (Object)

Returns:



24
25
26
# File 'lib/ruby_units/string.rb', line 24

def convert_to(other)
  to_unit.convert_to(other)
end

#format_with_unit(*other) ⇒ String Also known as: %

format unit output using formating codes

Examples:

‘%0.2f’ % ‘1 mm’.to_unit => ‘1.00 mm’

Returns:



13
14
15
16
17
18
19
# File 'lib/ruby_units/string.rb', line 13

def format_with_unit(*other)
  if other.first.is_a?(RubyUnits::Unit)
    other.first.to_s(self)
  else
    original_format(*other)
  end
end

#to_unit(other = nil) ⇒ Unit

make a string into a unit

Returns:



5
6
7
# File 'lib/ruby_units/string.rb', line 5

def to_unit(other = nil)
  other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self)
end