Class: FormReader::Select

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/web/formreader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelect

Returns a new instance of Select.



109
110
111
112
# File 'lib/web/formreader.rb', line 109

def initialize
  @options = Array.new
  @multiple = false
end

Instance Attribute Details

#multipleObject

Returns the value of attribute multiple.



108
109
110
# File 'lib/web/formreader.rb', line 108

def multiple
  @multiple
end

#optionsObject

Returns the value of attribute options.



108
109
110
# File 'lib/web/formreader.rb', line 108

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/web/formreader.rb', line 142

def == other
  if other.kind_of?(String) && self.to_a.length == 1
    other == self.to_a[0]
  else
    other == self.to_a
  end
end

#__index(key) ⇒ Object



156
157
158
# File 'lib/web/formreader.rb', line 156

def __index(key)
  self.to_a.__index(key)
end

#compare_includes?(haystack, prefix = []) ⇒ Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/web/formreader.rb', line 160

def compare_includes? haystack, prefix=[]
  self.to_a.compare_includes? haystack, prefix
end

#eachObject



134
135
136
137
138
# File 'lib/web/formreader.rb', line 134

def each
  options.each{ |option|
    yield option.value if option.selected
  }
end

#has_key?(index) ⇒ Boolean

these functions are the interface for assert_includes we delegate to the array… but also answer to the options hash

Returns:

  • (Boolean)


152
153
154
# File 'lib/web/formreader.rb', line 152

def has_key?(index)
  self.to_a.has_key?(index)
end

#make_option_from_element(element) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/web/formreader.rb', line 122

def make_option_from_element( element )
  value = element.attribute("value")
  unless value
    value = element.content.to_s
    value.gsub!( /<[^>]*>/, "" )
    value.strip!
  end
  Option.new( value,
              element.attribute("selected") || \
              element.attribute("checked") )
end

#push_option(option) ⇒ Object



118
119
120
# File 'lib/web/formreader.rb', line 118

def push_option( option )
  options.push(make_option_from_element(option))
end

#shift_option(option) ⇒ Object



114
115
116
# File 'lib/web/formreader.rb', line 114

def shift_option( option )
  options.unshift(make_option_from_element(option))
end