Class: Tableficate::Filter::Collection
- Inherits:
-
Array
- Object
- Array
- Tableficate::Filter::Collection
- Defined in:
- lib/tableficate/filters/collection.rb
Instance Method Summary collapse
-
#initialize(container, options = {}) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(container, options = {}) ⇒ Collection
Returns a new instance of Collection.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tableficate/filters/collection.rb', line 4 def initialize(container, = {}) container = container.to_a if container.is_a?(Range) selected = Array.wrap([:selected]).map{|item| item.to_s} disabled = Array.wrap([:disabled]).map{|item| item.to_s} container.map do |element| text, value, = case when Array === element html_attrs = element.detect {|e| Hash === e} || {} element = element.reject {|e| Hash === e} [element.first, element.last, html_attrs] when !element.is_a?(String) && element.respond_to?(:first) && element.respond_to?(:last) [element.first, element.last, {}] else [element, element, {}] end [:selected] = 'selected' if selected.include?(value.to_s) [:disabled] = 'disabled' if disabled.include?(value.to_s) self.push(Choice.new(text, value, )) end end |