class AMEE::DataAbstraction::Usage
Subclass of Input
providing methods and attributes appropriate for representing adjustable calculation usages specifically.
Only one instance of Usage can be assocaited with a particular calucaltion object. When the value of self
is changed, profile item value terms which are forbidden in the new usage will be inactivated and optional/compulsory flags are set on the remaining terms.
Public Class Methods
Initialization of Usage objects follows that of the parent Input class, with a number of differences.
If the parent caluclation already contains a usage term, a TwoUsages exception is raised.
The label<tt> attribute is set by default to <tt>:usage
.
The interface
attribute of self
is set to :drop_down
by default, but can be manually configured if required.
The inactive
property of self
is set to :invisible
by default.
AMEE::DataAbstraction::Input::new
# File lib/amee-data-abstraction/usage.rb, line 34 def initialize(options={},&block) raise Exceptions::TwoUsages if options[:parent].current_usage label :usage @inactive=:invisible super interface :drop_down unless interface end
Public Instance Methods
Activate and deactivate terms in the parent calculation according to the compulsory/optional/forbidden status’ of each in the usage indicated by usage
# File lib/amee-data-abstraction/usage.rb, line 65 def activate_selected(usage=nil) parent.profiles.in_use(usage).each do |term| case @inactive when :invisible term.show! when :disabled term.enable! end end parent.profiles.out_of_use(usage).each do |term| case @inactive when :invisible term.hide! when :disabled term.disable! end end end
Returns an array of available valid values for self
.
# File lib/amee-data-abstraction/usage.rb, line 85 def choices parent.amee_usages end
Adjust the value of self
indicating that a new usage should be switch to in the parent caluclation. This method has the effect of (de)activating terms in the parent calculation as appropriate.
AMEE::DataAbstraction::Input#value
# File lib/amee-data-abstraction/usage.rb, line 53 def value(*args) unless args.empty? @value=args.first activate_selected(value) end super end