Class: Chop::Form::Field

Inherits:
Struct
  • Object
show all
Defined in:
lib/chop/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldObject

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



44
45
46
# File 'lib/chop/form.rb', line 44

def field
  @field
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



44
45
46
# File 'lib/chop/form.rb', line 44

def label
  @label
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



44
45
46
# File 'lib/chop/form.rb', line 44

def path
  @path
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



44
45
46
# File 'lib/chop/form.rb', line 44

def session
  @session
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



44
45
46
# File 'lib/chop/form.rb', line 44

def value
  @value
end

Class Method Details

.candidatesObject



58
59
60
61
62
# File 'lib/chop/form.rb', line 58

def self.candidates
  descendants.sort_by do |a|
    a == Chop::Form::Default ? 1 : -1 # ensure Default comes last
  end
end

.for(session, label, value, path) ⇒ Object



45
46
47
48
49
50
# File 'lib/chop/form.rb', line 45

def self.for session, label, value, path
  field = session.find_field(label)
  candidates.map do |klass|
    klass.new(session, label, value, path, field)
  end.find(&:matches?)
end

.from(session, field) ⇒ Object



52
53
54
55
56
# File 'lib/chop/form.rb', line 52

def self.from session, field
  candidates.map do |klass|
    klass.new(session, nil, nil, nil, field)
  end.find(&:matches?)
end

Instance Method Details

#get_valueObject



64
65
66
# File 'lib/chop/form.rb', line 64

def get_value
  field.value
end