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.



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

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

Instance Attribute Details

#multipleObject

Returns the value of attribute multiple.



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

def multiple
  @multiple
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



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

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



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

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

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

Returns:

  • (Boolean)


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

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

#eachObject



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

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)


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

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

#make_option_from_element(element) ⇒ Object



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

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



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

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

#shift_option(option) ⇒ Object



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

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