Class: AMEE::DataAbstraction::Drill

Inherits:
Input
  • Object
show all
Defined in:
lib/amee-data-abstraction/drill.rb

Overview

Subclass of Input providing methods and attributes appropriate for representing AMEE drill down choices and selections specifically

Constant Summary

Constants inherited from Term

Term::Interfaces, Term::UnitFields

Instance Attribute Summary

Attributes inherited from Input

#dirty

Attributes inherited from Term

#parent, #value_before_cast

Instance Method Summary collapse

Methods inherited from Input

#choice_validation_message, #clean!, #compulsory!, #compulsory?, #dirty?, #fixed, #fixed?, #invalid, #optional!, #optional?, #options_for_select, #validate!, #validation, #validation_message, #value

Methods inherited from Term

#==, #after?, #before?, #convert_unit, convert_value_to_type, #disable!, #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) ⇒ Drill

Initialization of Drill objects follows that of the parent Input class. The interface attribute of self is set to :drop_down by default for Drill instances, but can be manually configured if required.



32
33
34
35
36
# File 'lib/amee-data-abstraction/drill.rb', line 32

def initialize(options={},&block)
  interface :drop_down
  super
  choice_validation_message
end

Instance Method Details

#choices(*args) ⇒ Object

Returns the list of available choices for self. A custom list of choices can be provided as an argument, in which case these will override the list provided by the AMEE platform



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/amee-data-abstraction/drill.rb', line 42

def choices(*args)
  if args.empty?
    if @choices.blank?
      drill_down = parent.amee_drill(:before=>label)
      if single_choice = drill_down.selections[path]
        disable!
        [single_choice]
      else
        enable!
        drill_down.choices
      end
    else
      @choices
    end
  else
    @choices = [args].flatten
  end
end

#disabled?Boolean

Returns true if the UI element of self is disabled. Otherwise, returns false.

A drill is considered disabled if it either (1) explicitly set using the #disable! method; (2) has a fixed value; or (3) is not the next drill (because drill should be chosen in order).

Returns:

  • (Boolean)


23
24
25
# File 'lib/amee-data-abstraction/drill.rb', line 23

def disabled?
  super || (!set? && !next?)
end