Class: FormReader::Select
- Includes:
- Enumerable
- Defined in:
- lib/web/formreader.rb
Instance Attribute Summary collapse
-
#multiple ⇒ Object
Returns the value of attribute multiple.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #__index(key) ⇒ Object
- #compare_includes?(haystack, prefix = []) ⇒ Boolean
- #each ⇒ Object
-
#has_key?(index) ⇒ Boolean
these functions are the interface for assert_includes we delegate to the array…
-
#initialize ⇒ Select
constructor
A new instance of Select.
- #make_option_from_element(element) ⇒ Object
- #push_option(option) ⇒ Object
- #shift_option(option) ⇒ Object
Constructor Details
Instance Attribute Details
#multiple ⇒ Object
Returns the value of attribute multiple.
108 109 110 |
# File 'lib/web/formreader.rb', line 108 def multiple @multiple end |
#options ⇒ Object
Returns the value of attribute options.
108 109 110 |
# File 'lib/web/formreader.rb', line 108 def @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
160 161 162 |
# File 'lib/web/formreader.rb', line 160 def compare_includes? haystack, prefix=[] self.to_a.compare_includes? haystack, prefix end |
#each ⇒ Object
134 135 136 137 138 |
# File 'lib/web/formreader.rb', line 134 def each .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
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 ) .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 ) .unshift(make_option_from_element(option)) end |