class AMEE::DataAbstraction::Drill

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

Public Class Methods

new(options={},&block) click to toggle source

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.

Calls superclass method
# File lib/amee-data-abstraction/drill.rb, line 32
def initialize(options={},&block)
  interface :drop_down
  super
  choice_validation_message
end

Public Instance Methods

choices(*args) click to toggle source

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

# 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?() click to toggle source

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).

Calls superclass method
# File lib/amee-data-abstraction/drill.rb, line 23
def disabled?
  super || (!set? && !next?)
end

Private Instance Methods

next?() click to toggle source

Returns true if self is the “first unset” drill, i.e. the one which should be set next

# File lib/amee-data-abstraction/drill.rb, line 73
def next?
  unset? && parent.drills.before(label).all?(&:set?)
end
valid?() click to toggle source

Returns true if the value set for self is one of the available choices. Otherwise, returns false.

Calls superclass method
# File lib/amee-data-abstraction/drill.rb, line 66
def valid?
  super && (choices.include? value)
end