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.
-
#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
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 |
#units ⇒ Object
attr_reader
212 213 214 |
# File 'lib/mathviz.rb', line 212 def units @unit || MathViz::Unit.new end |
#with_units ⇒ Object
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 |