Class: HtmlCom::Dropdown
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- HtmlCom::Dropdown
- Defined in:
- lib/htmlcom.rb
Instance Method Summary collapse
-
#initialize(rawoptions = [], options: rawoptions, label: nil, id: nil) ⇒ Dropdown
constructor
A new instance of Dropdown.
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.
390 391 392 393 394 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 |
# File 'lib/htmlcom.rb', line 390 def initialize(=[], options: , label: nil, id: nil) @tag = 'dropdown' @htmltag = 'select' @id = id @label = label if .is_a? Array then list = .map {|option| {option: option}} super({_select: list}) values = .map(&:downcase) @doc.root.xpath('dropdown/select/option').each.with_index do |e,i| e.attributes[:value] = values[i] end elsif .is_a? Hash then list = .values.map {|option| {option: option}} values = .keys super({_select: list}) @doc.root.xpath('dropdown/select/option').each.with_index do |e,i| e.attributes[:value] = values[i] end end end |