Class: String

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

Instance Method Summary collapse

Instance Method Details

#%(*args) ⇒ String

format unit output using formating codes

Examples:

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

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_units/string.rb', line 16

def %(*args)
return "" if self.empty?
  case 
  when args.first.is_a?(RubyUnits::Unit)
    args.first.to_s(self)
  when (!defined?(Uncertain).nil? && args.first.is_a?(Uncertain))
    args.first.to_s(self)
  when args.first.is_a?(Complex)
    args.first.to_s
  else
    unit_format(*args)
  end
end

#convert_to(other) ⇒ Unit

Parameters:

Returns:



32
33
34
# File 'lib/ruby_units/string.rb', line 32

def convert_to(other)
  self.unit.convert_to(other)
end

#to_unit(other = nil) ⇒ Unit Also known as: unit, u

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

#unit_formatObject



12
# File 'lib/ruby_units/string.rb', line 12

alias :unit_format :%