Module: MathViz::Measured
Overview
Something (i.e. MathViz::Term) which has MathViz::Units.
Instance Method Summary collapse
-
#per ⇒ Object
Statefull toggle numerator/denominator of unit assignment; e.g.
-
#to_value ⇒ Object
api method for unwrapping terms.
-
#unit(x) ⇒ Object
Add the named unit to our units and return self.
-
#units ⇒ Object
attr_reader.
-
#with_units ⇒ Object
Return a string representation of the units portion, with space if applicable.
Methods included from Units::Class
Instance Method Details
#per ⇒ Object
Statefull toggle numerator/denominator of unit assignment; e.g. m/s = .m.per.s
268 269 270 271 272 |
# File 'lib/mathviz.rb', line 268 def per @unit_sign ||= 1 @unit_sign *= -1 self end |
#to_value ⇒ Object
api method for unwrapping terms
280 281 282 |
# File 'lib/mathviz.rb', line 280 def to_value to_f end |
#unit(x) ⇒ Object
Add the named unit to our units and return self. See also MathViz::Units::Class#new_units
256 257 258 259 260 261 262 263 264 265 |
# File 'lib/mathviz.rb', line 256 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 |
#units ⇒ Object
attr_reader
275 276 277 |
# File 'lib/mathviz.rb', line 275 def units @unit || MathViz::Unit.new end |
#with_units ⇒ Object
Return a string representation of the units portion, with space if applicable
246 247 248 249 250 251 252 253 |
# File 'lib/mathviz.rb', line 246 def with_units u = units.to_s if (u.empty?) u else ' ' + u end end |