Class: AMEE::DataAbstraction::Profile
- Defined in:
- lib/amee-data-abstraction/profile.rb
Overview
Subclass of Input
providing methods and attributes appropriate for representing AMEE profile item values specifically
Constant Summary
Constants inherited from Term
Term::Interfaces, Term::UnitFields
Instance Attribute Summary
Attributes inherited from Input
Attributes inherited from Term
Instance Method Summary collapse
-
#amee_ivd ⇒ Object
Return the AMEE::Admin::ItemValueDefinition object associated with
self
. -
#compulsory?(usage = nil) ⇒ Boolean
Return
true
if the value ofself
is required before the parent calculation can be calculated. -
#in_use?(usage) ⇒ Boolean
Return
true
if the value ofself
is either compulsory OR optional in the owning calculation, i.e. -
#initialize(options = {}, &block) ⇒ Profile
constructor
Initialization of Input objects follows that of the parent Term class.
-
#optional?(usage = nil) ⇒ Boolean
Return
true
if the value ofself
is NOT required before the parent calculation can be calculated. -
#out_of_use?(usage) ⇒ Boolean
Return
true
if the value ofself
is neither compulsory OR optional in the owning calculation, i.e. -
#valid? ⇒ Boolean
Returns
true
if the value set forself
is valid.
Methods inherited from Input
#choice_validation_message, #choices, #clean!, #compulsory!, #dirty?, #disabled?, #fixed, #fixed?, #invalid, #optional!, #options_for_select, #validate!, #validation, #validation_message, #value
Methods inherited from Term
#==, #after?, #before?, #convert_unit, convert_value_to_type, #disable!, #disabled?, #enable!, #enabled?, #has_numeric_value?, #hidden?, #hide!, #initialize_copy, #inspect, #interface, #is_numeric?, #note, #set?, #show!, #to_quantity, #to_s, #unset?, validate_dimensional_equivalence?, #value, #visible?
Constructor Details
#initialize(options = {}, &block) ⇒ Profile
Initialization of Input objects follows that of the parent Term class. The interface
attribute of self
is set to :drop_down
by default if a list of choices is defined using the choices
attribute. Otherwise the interface
attribute is set to :test_box
, but can be manually configured if required.
35 36 37 38 39 40 |
# File 'lib/amee-data-abstraction/profile.rb', line 35 def initialize(={},&block) super interface :drop_down unless choices.blank? unless choices.blank? interface :text_box unless interface end |
Instance Method Details
#amee_ivd ⇒ Object
Return the AMEE::Admin::ItemValueDefinition object associated with self
.
92 93 94 |
# File 'lib/amee-data-abstraction/profile.rb', line 92 def amee_ivd parent.amee_ivds.detect{|x|x.path==path} end |
#compulsory?(usage = nil) ⇒ Boolean
Return true
if the value of self
is required before the parent calculation can be calculated. Otherwise, return false
.
If no argument is provided, compulsory status is determined according to the current usage of the parent calculation. Compulsory status can be determined for a specific usage by passing in the usage path as an argument
61 62 63 64 |
# File 'lib/amee-data-abstraction/profile.rb', line 61 def compulsory?(usage=nil) usage||=parent.current_usage usage ? amee_ivd.compulsory?(usage) : super() end |
#in_use?(usage) ⇒ Boolean
Return true
if the value of self
is either compulsory OR optional in the owning calculation, i.e. is NOT forbidden.
If no argument is provided, the optional/compulsory status is defined according to the current usage of the parent caluclation. Otherwise, optional/compulsory status is determined on the basis of the usage whose AMEE platform path matches usage
74 75 76 |
# File 'lib/amee-data-abstraction/profile.rb', line 74 def in_use?(usage) compulsory?(usage)||optional?(usage) end |
#optional?(usage = nil) ⇒ Boolean
Return true
if the value of self
is NOT required before the parent calculation can be calculated. Otherwise, return false
.
If no argument is provided, optional status is determined according to the current usage of the parent calculation. Optionality can be determined for a specific usage by passing in the usage path as an argument
49 50 51 52 |
# File 'lib/amee-data-abstraction/profile.rb', line 49 def optional?(usage=nil) usage||=parent.current_usage usage ? amee_ivd.optional?(usage) : super() end |
#out_of_use?(usage) ⇒ Boolean
Return true
if the value of self
is neither compulsory OR optional in the owning calculation, i.e. is forbidden.
If no argument is provided, forbbiden status is defined according to the current usage of the parent caluclation. Otherwise, it is determined on the basis of the usage whose AMEE platform path matches usage
85 86 87 |
# File 'lib/amee-data-abstraction/profile.rb', line 85 def out_of_use?(usage) !in_use?(usage) end |
#valid? ⇒ Boolean
Returns true
if the value set for self
is valid. If self
contains neither a custom validation pattern nor any defined choices, true
is returned. Otherwise, validity depends on the custom validation being successful (if present) and the the value of self
matching one of the entries in the choices
attribute (if defined). Otherwise, returns false
.
103 104 105 |
# File 'lib/amee-data-abstraction/profile.rb', line 103 def valid? super && (choices.blank? || choices.include?(value)) end |