Class: HtmlCom::Dropdown

Inherits:
InputElement show all
Defined in:
lib/htmlcom.rb

Instance Method Summary collapse

Methods inherited from Element

#html_element, #to_doc, #to_html

Constructor Details

#initialize(rawoptions = [], options: rawoptions, label: nil, id: nil) ⇒ Dropdown

Returns a new instance of Dropdown.



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/htmlcom.rb', line 395

def initialize(rawoptions=[], options: rawoptions, label: nil, id: nil)

  @tag = 'dropdown'
  @htmltag = 'select'
  @id = id
  @label = label

  if options.is_a? Array then

    list = options.map {|option| {option: option}}
    super({_select: list})

    values = options.map(&:downcase)
    @doc.root.xpath('dropdown/select/option').each.with_index do |e,i|
      e.attributes[:value] = values[i]
    end

  elsif options.is_a? Hash then

    list = options.values.map {|option| {option: option}}
    values = options.keys
    super({_select: list})

    @doc.root.xpath('dropdown/select/option').each.with_index do |e,i|
      e.attributes[:value] = values[i]
    end


  end
end