Sha256: 0174cba6f549ab73f9d38252e6f9b658a59edd7c1e89a48f2ad04a90d9d0cbe5

Contents?: true

Size: 966 Bytes

Versions: 16

Compression:

Stored size: 966 Bytes

Contents

require "chop/diff"
      
module Chop
  class DefinitionList < Diff
    self.default_selector = "dl"
    self.rows_finder = ->(root) do
      root.all("dt,dd").slice_before do |node|
        node.tag_name == "dt"
      end
    end
    self.cells_finder = ->(row) { row }

    def column index, &block
      transformation do |rows|
        rows.map.with_index do |row, row_index|
          row[index] = block.call(row[index]) if row.length > index
          row
        end
      end
    end

    def field key
      transformation do |rows|
        rows.map do |row|
          if row.first.text.parameterize.underscore == key.to_s
            row[1] = yield(row[1])
          end
          row
        end
      end
    end

    def image *cols
      block = ->(cell){ cell_to_image_filename(cell) }
      cols.each do |col|
        method = col.is_a?(Symbol) ? :field : :column
        send method, col, &block
      end
    end
  end

  Dl = DefinitionList
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
chop-0.31.0 lib/chop/definition_list.rb
chop-0.30.0 lib/chop/definition_list.rb
chop-0.29.0 lib/chop/definition_list.rb
chop-0.28.1 lib/chop/definition_list.rb
chop-0.28.0 lib/chop/definition_list.rb
chop-0.27.0 lib/chop/definition_list.rb
chop-0.26.1 lib/chop/definition_list.rb
chop-0.26.0 lib/chop/definition_list.rb
chop-0.25.2 lib/chop/definition_list.rb
chop-0.25.1 lib/chop/definition_list.rb
chop-0.25.0 lib/chop/definition_list.rb
chop-0.24.0 lib/chop/definition_list.rb
chop-0.23.8 lib/chop/definition_list.rb
chop-0.23.7 lib/chop/definition_list.rb
chop-0.23.6 lib/chop/definition_list.rb
chop-0.23.5 lib/chop/definition_list.rb