Sha256: efe381f2037e476281963b8a8e815fd068aa0a698092cdcd14380e69eca31bcd

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

module Druid
  module Elements
    class TableRow < Element

      #
      # Return the Druid::Elements::TableCell for the index provided. Index
      # is zero based. If the index provided is a String then it
      # will be matched with the text from the columns in the first row.
      #
      def [](idx)
        idx = find_index_by_title(idx) if idx.kind_of?(String)
        return nil unless idx
        Druid::Elements::TableCell.new(element[idx])
      end
      #
      # Returns the number of rows in the table.
      #
      def columns
        element.cells.size
      end

      def each
        for index in 1..self.columns do
          yield self[index-1]
        end
      end

      private

      def find_index_by_title(title)
        table = element.parent
        first_row = table[0]
        first_row.cells.find_index { |column| column.text.include? title}
      end

    end

    Druid::Elements.tag_to_class[:tr] = Druid::Elements::TableRow

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
druid-ts-1.1.4 lib/druid/elements/table_row.rb