Sha256: 2ab4cfae1d1b2a31fbec10f83435d9e6bf1071120e8a03f8b66cb979e9f7c841

Contents?: true

Size: 874 Bytes

Versions: 1

Compression:

Stored size: 874 Bytes

Contents

require "delegate"
      
module Chop
  class UnorderedList < SimpleDelegator
    def self.diff! table, &block
      new.diff! table
    end

    def initialize selector = "ul", session: Capybara.current_session
      super(session)
      @selector = selector
    end

    def to_a
      rows.collect do |row|
        row_to_text(row)
      end
    end

    def normalized_to_a
      raw = to_a
      max = raw.map(&:count).max
      raw.select { |row| row.count == max }
    end

    def diff! table
      table.diff! normalized_to_a
    end

    private

    def rows
      node.all("li")
    end

    def node
      @node ||= find(@selector)
    end

    def row_to_text row
      [row].collect do |cell|
        text = cell.text
        if text.blank? and image = cell.all("img").first
          text = image["alt"]
        end
        text
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chop-0.7.0 lib/chop/unordered_list.rb