Module: NumericWithUnit::CORE_EXT::String

Defined in:
lib/numeric_with_unit/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_nwu(mthd = :to_r) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/numeric_with_unit/core_ext.rb', line 14

def to_nwu(mthd=:to_r)
  # TODO: 適当なのでもう少しいい感じに。いい感じに
  m = self.match /.*?(?=[\s\(\[])/
  value = m.to_s
  unit = m.post_match.strip.gsub(/^\[|\]$/, '')
  NumericWithUnit.new(value.__send__(mthd), unit)
end