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.
109 110 111 |
# File 'lib/web/formreader.rb', line 109 def multiple @multiple end |
#options ⇒ Object
Returns the value of attribute options.
109 110 111 |
# File 'lib/web/formreader.rb', line 109 def @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
161 162 163 |
# File 'lib/web/formreader.rb', line 161 def compare_includes? haystack, prefix=[] self.to_a.compare_includes? haystack, prefix end |
#each ⇒ Object
135 136 137 138 139 |
# File 'lib/web/formreader.rb', line 135 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
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 ) .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 ) .unshift(make_option_from_element(option)) end |