Sha256: 95346ac6228af9a2b549b57e4f90c99250792d558fedfd17e8b902c28dd377a3

Contents?: true

Size: 532 Bytes

Versions: 7

Compression:

Stored size: 532 Bytes

Contents

module TableSortable
  class Columns < Array

    def initialize
      super
    end

    def add(col_name, *options)
      options = options.extract_options!
      self << TableSortable::Column.new(col_name, options)
    end

    def sort_by(sort_key)
      if sort_key
        sort_key.map{|c| self.find{|col| (c.is_a?(String) ? (col.label == c) : col.name == c)}}
      else
        self
      end
    end

    def [](name)
      return self.find{|col| col.name == name.to_sym} if name.is_a? String
      super
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
table_sortable-1.0.0.pre.alpha.11 lib/table_sortable/columns.rb
table_sortable-1.0.0.pre.alpha.10 lib/table_sortable/columns.rb
table_sortable-1.0.0.pre.alpha.9 lib/table_sortable/columns.rb
table_sortable-1.0.0.pre.alpha.8 lib/table_sortable/columns.rb
table_sortable-1.0.0.pre.alpha.7 lib/table_sortable/columns.rb
table_sortable-1.0.0.pre.alpha.6 lib/table_sortable/columns.rb
table_sortable-1.0.0.pre.alpha.5 lib/table_sortable/columns.rb