Module: MathViz::Measured

Includes:
Units
Included in:
Term
Defined in:
lib/mathviz.rb

Overview

Something (i.e. MathViz::Term) which has MathViz::Units.

Instance Method Summary collapse

Methods included from Units::Class

#included, #new_units

Instance Method Details

#perObject

Statefull toggle numerator/denominator of unit assignment; e.g. m/s = .m.per.s



205
206
207
208
209
# File 'lib/mathviz.rb', line 205

def per
  @unit_sign ||= 1
  @unit_sign *= -1
  self
end

#unit(x) ⇒ Object

Add the named unit to our units and return self. See also MathViz::Units::Class#new_units



193
194
195
196
197
198
199
200
201
202
# File 'lib/mathviz.rb', line 193

def unit(x)
  @unit ||= MathViz::Unit.new
  @unit_sign ||= 1
  if (@unit_sign > 0)
    @unit *= MathViz::Unit.new(x)
  else
    @unit /= MathViz::Unit.new(x)
  end
  self
end

#unitsObject

attr_reader



212
213
214
# File 'lib/mathviz.rb', line 212

def units
  @unit || MathViz::Unit.new
end

#with_unitsObject

Return a string representation of the units portion, with space if applicable



183
184
185
186
187
188
189
190
# File 'lib/mathviz.rb', line 183

def with_units
  u = units.to_s
  if (u.empty?)
    u
  else
    ' ' + u
  end
end