Class: WebUnit::Select

Inherits:
Param show all
Defined in:
lib/webunit/params.rb

Instance Attribute Summary collapse

Attributes inherited from Param

#name, #relations, #stat, #type

Attributes inherited from HtmlElem

#array, #attrs, #children, #data, #name, #tag

Instance Method Summary collapse

Methods inherited from Param

#update

Methods inherited from HtmlElem

#append, #extract, #find, #has?, #inspect, #print, #readlink, #search

Constructor Details

#initialize(ah) ⇒ Select

Returns a new instance of Select.



153
154
155
156
157
158
# File 'lib/webunit/params.rb', line 153

def initialize( ah )
  super( 'select', ah )
  @options = []
  @size = ah["size"]
  @type = 'select'
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



151
152
153
# File 'lib/webunit/params.rb', line 151

def options
  @options
end

Instance Method Details

#add_option(option) ⇒ Object



160
161
162
# File 'lib/webunit/params.rb', line 160

def add_option( option )
  @options.push( option )
end

#end_optionObject



164
165
166
167
168
# File 'lib/webunit/params.rb', line 164

def end_option
  if @size == nil && @options.reject { |o| o.stat == 'off' } == []
    @options[0].select
  end
end

#multipart_query_data(boundary) ⇒ Object



193
194
195
196
197
198
199
200
201
# File 'lib/webunit/params.rb', line 193

def multipart_query_data( boundary)
  lines = ''
  @options.each do |o|
    data = o.multipart_query_data(boundary, @name)
    lines << data if data
  end
  
  lines
end

#query_dataObject



184
185
186
187
188
189
190
191
# File 'lib/webunit/params.rb', line 184

def query_data
  a = []
  @options.each do |o|
    a << o.query_data( @name )
  end
  s = a.compact.join('&')
  s == '' ? nil : s
end

#select(arr) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/webunit/params.rb', line 170

def select( arr )
  @options.each do |o|
    o.deselect
  end
  arr.each do |e|
    @options[e].select if e.kind_of?( Integer )
    if e.kind_of?( String )
      @options.each do |o|
        o.select if o.value == e || o.data == e
      end
    end
  end
end

#valueObject



203
204
205
206
207
208
209
210
211
212
213
# File 'lib/webunit/params.rb', line 203

def value
  arr = []
  @options.each do |o|
    arr << o.value if o.stat == 'on'
  end
  case arr.size
    when 0 then nil
    when 1 then arr[0]
    else arr
  end
end

#value=(v) ⇒ Object



215
216
217
218
219
220
221
222
223
# File 'lib/webunit/params.rb', line 215

def value= ( v )
  @options.each do |o|
    if o.value == v
      o.select
    else
      o.deselect
    end
  end
end