Class: AMEE::Db::Term
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AMEE::Db::Term
- Defined in:
- lib/amee/db/term.rb
Overview
This class represents a database record for a calculation term used with the AMEE:DataAbstraction::OngoingCalculation class. This class stores the label, value and unit attributes of specific calculation terms, and is owned by an associated AMEE::Db::Calculation record
This class is typically used by proxy, via the #update_calculation!
, and #to_hash
methods of the AMEE::Db::Calculation class, and ultimately called from the find
, find_by_type
, #save
, #delete
, and #get_db_calculation
methods associated with the AMEE:DataAbstraction::OngoingCalculation class.
Instance Method Summary collapse
-
#to_hash ⇒ Object
Returns a Hash representation of
self
, e.g.
Instance Method Details
#to_hash ⇒ Object
Returns a Hash representation of self
, e.g.
my_term.to_hash #=> { :value => 1600,
:unit => <Quantify::Unit::SI> }
my_term.to_hash #=> { :value => 234.1,
:unit => <Quantify::Unit::NonSI>,
:per_unit => <Quantify::Unit::SI> }
This method is called as part of AMEE::Db::Calculation#to_hash
in order to provide a full hash representation of a calculation.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/amee/db/term.rb', line 40 def to_hash sub_hash = {} # Float method called on term value in order to initialize # explicitly numeric values as numeric objects. # sub_hash[:value] = AMEE::DataAbstraction::Term.convert_value_to_type(self.value, self.value_type) sub_hash[:unit] = Unit.for(unit) if unit sub_hash[:per_unit] = Unit.for(per_unit) if per_unit { label.to_sym => sub_hash } end |