lib/amee-data-abstraction/term.rb in amee-data-abstraction-1.0.0 vs lib/amee-data-abstraction/term.rb in amee-data-abstraction-1.1.0
- old
+ new
@@ -339,10 +339,16 @@
# Declare that the term's UI element should be shown in generated UIs.
def show!
@visible=true
end
+ def ==(other_term)
+ !TermsList::TermProperties.inject(false) do |boolean,prop|
+ boolean || self.send(prop) != other_term.send(prop)
+ end
+ end
+
# Returns <tt>true</tt> if <tt>self</tt> has a numeric value. That is, can
# it have statistics applied? This method permits handling of term summing,
# averaging, etc. Otherwise, returns <tt>false</tt>.
#
def has_numeric_value?
@@ -460,18 +466,14 @@
# my_term.to_s :pluralized_name #=> "12345 tons"
#
# my_term.to_s :label #=> "12345 ton_us"
#
def to_s(format=:symbol)
- string = "#{value}"
- if unit and per_unit
- string += " #{(unit/per_unit).send(format)}"
- elsif unit
- string += " #{unit.send(format)}"
- elsif per_unit
- string += " #{(1/per_unit).send(format)}"
+ if has_numeric_value? && (unit || per_unit)
+ self.to_quantity.to_s(format)
+ else
+ "#{value}"
end
- return string
end
# Checks that the units included in <tt>units</tt> are dimensionally
# equivalent, that is, that they represent the same physucal quantity
#
\ No newline at end of file