Sha256: be389f44b4e0ed879694a8e602cff0ed605f0109bac92477088785425286ee91

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

module Mohawk
  module Accessors
    class TableRow
      include RAutomation::Adapter::MsUia

      attr_reader :row

      def initialize(table, row_index)
        @table = table
        @row = Row.new(@table.view, :index => row_index)
      end

      def selected?
        @table.view.selected? row.row
      end

      def select
        @table.view.select row.row
      end

      def cells
        row.cells.map &:text
      end

      def all_match?(hash)
        hash.all? do |key, value|
          send(key) == "#{value}"
        end
      end

      def value_from_header(name)
        which_column = header_methods.index(name)
        raise ArgumentError, "#{name} column does not exist in #{header_methods}" if which_column.nil?
        Cell.new(row, :index => which_column).text
      end
      
      def method_missing(name, *args)
        value_from_header name
      end

      def to_hash
        {:text => row.text, :row => row.row }
      end

      private
      def header_methods
        @headers ||= @table.headers.map(&:to_method)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mohawk-0.0.9 lib/mohawk/accessors/table_row.rb
mohawk-0.0.8 lib/mohawk/accessors/table_row.rb
mohawk-0.0.7 lib/mohawk/accessors/table_row.rb
mohawk-0.0.6 lib/mohawk/accessors/table_row.rb
mohawk-0.0.5 lib/mohawk/accessors/table_row.rb