Class: AMEE::DataAbstraction::Calculation
- Inherits:
-
Object
- Object
- AMEE::DataAbstraction::Calculation
- Defined in:
- lib/amee-data-abstraction/calculation.rb
Overview
Base class providing attributes and methods for representing a calculation which can be made using the AMEE platform. An instance of Calculation will typically be associated with a specific AMEE category.
Instances of Calculation are represented by several primary attributes:
label:: Symbol representing the unique, machine-readable name for the
calculation
name:: String representing a human-readable name for the calculation
path:: String representing the AMEE platform path to the data category
which is associated with <tt>self</tt>
fixed_usage:: String representing the AMEE platform path for the usage to
be used by <tt>self</tt>, if defined
An instance of Calculation also holds an arbitrary number of objects of the class Term. These represent values associated with the calculation, e.g. inputs, outputs, metadatum, etc. These can be accessed using the #terms
methods or the term subset methods provided by the TermsList
class (e.g. #profiles
, #visible
)
Two classes inherit the Calculation class:
-
PrototypeCalculation : provides a templating for a specific calculation type with defined, but blank, terms (i.e. inputs, outputs, etc.)
-
OngoingCalculation : represents a particular calculation - possibly incomplete - which can be updated, submitted for calculation, and saved
Direct Known Subclasses
Instance Attribute Summary collapse
-
#contents ⇒ Object
Retrieve the terms associated with
self
as a hash from labels to terms.
Instance Method Summary collapse
-
#[](sym) ⇒ Object
Shorthand method for retrieving the term assocaited with
self
which has a label matchingsym
. -
#amee_ivds ⇒ Object
Return the AMEE::Admin::ItemValueDefinitionList object associated with
self
. -
#amee_usages ⇒ Object
Returns an Array containing the AMEE platform paths for all valid usage available to
self
according to those defined under #item_definition. -
#current_usage ⇒ Object
Returns a String representing the AMEE platform path for the usage currently used by
self
. -
#discover_url ⇒ Object
Return a string representing the AMEE Explorer URL which is assocaited with
self
. - #explorer_url ⇒ Object
- #initialize_copy(source) ⇒ Object
-
#inspect ⇒ Object
Prettyprint a string representation of
self
, together with associated terms. -
#terms ⇒ Object
Calculations contain a list of “terms” of the base class Term, representing inputs, outputs, metadatum, etc.
Instance Attribute Details
#contents ⇒ Object
Retrieve the terms associated with self
as a hash from labels to terms.
94 95 96 |
# File 'lib/amee-data-abstraction/calculation.rb', line 94 def contents @contents end |
Instance Method Details
#[](sym) ⇒ Object
Shorthand method for retrieving the term assocaited with self
which has a label matching sym
99 100 101 |
# File 'lib/amee-data-abstraction/calculation.rb', line 99 def [](sym) @contents[sym.to_sym] end |
#amee_ivds ⇒ Object
Return the AMEE::Admin::ItemValueDefinitionList object associated with self
. This represents each of the item value definitions which are associated with the calculation
216 217 218 |
# File 'lib/amee-data-abstraction/calculation.rb', line 216 def amee_ivds @amee_ivds||=amee_item_definition.item_value_definition_list.select{|x|x.versions.include?("2.0")} end |
#amee_usages ⇒ Object
Returns an Array containing the AMEE platform paths for all valid usage available to self
according to those defined under #item_definition. If no usage(s) is defined, returns nil, e.g.
my_calculation.amee_usages #=> [ 'byMass', 'byEnergy' ]
235 236 237 |
# File 'lib/amee-data-abstraction/calculation.rb', line 235 def amee_usages @amee_usages||=amee_item_definition.usages end |
#current_usage ⇒ Object
Returns a String representing the AMEE platform path for the usage currently used by self
. If not usage is defined, returns nil
my_calculation.current_usage #=> 'byMass'
225 226 227 |
# File 'lib/amee-data-abstraction/calculation.rb', line 225 def current_usage usages.empty? ? fixed_usage : usages.first.value end |
#discover_url ⇒ Object
Return a string representing the AMEE Explorer URL which is assocaited with self
130 131 132 |
# File 'lib/amee-data-abstraction/calculation.rb', line 130 def discover_url "http://discover.amee.com/categories#{path}" end |
#explorer_url ⇒ Object
134 135 136 137 |
# File 'lib/amee-data-abstraction/calculation.rb', line 134 def explorer_url ::Rails.logger.info "#explorer_url method deprecated. Use #discover_url" if defined?(Rails) && ::Rails.logger.present? discover_url end |
#initialize_copy(source) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/amee-data-abstraction/calculation.rb', line 118 def initialize_copy(source) super @contents=ActiveSupport::OrderedHash.new source.contents.each do |k,v| @contents[k]=v.clone @contents[k].parent=self end end |
#inspect ⇒ Object
Prettyprint a string representation of self
, together with associated terms
112 113 114 115 116 |
# File 'lib/amee-data-abstraction/calculation.rb', line 112 def inspect elements = {:label => label.inspect, :terms => terms.map{|t| "<#{t.class.name.demodulize} label:#{t.label}, value:#{t.value.inspect}>"}} attr_list = elements.map {|k,v| "#{k}: #{v}" } * ', ' "<#{self.class.name} #{attr_list}>" end |
#terms ⇒ Object
Calculations contain a list of “terms” of the base class Term, representing inputs, outputs, metadatum, etc. which are associated with self
.
Returns all associated terms as an instance of the TermsList class
89 90 91 |
# File 'lib/amee-data-abstraction/calculation.rb', line 89 def terms TermsList.new(@contents.values) end |