Class: Chop::DefinitionList

Inherits:
Diff
  • Object
show all
Defined in:
lib/chop/definition_list.rb

Direct Known Subclasses

DfnDl

Instance Attribute Summary

Attributes inherited from Diff

#block, #header_transformations, #selector, #session, #table, #timeout, #transformations

Instance Method Summary collapse

Methods inherited from Diff

#allow_not_found, #cell_to_image_filename, #cells, diff!, #diff!, #hash_transformation, #header, #header_transformation, #initialize, #rows, #text, #to_a, #transformation

Constructor Details

This class inherits a constructor from Chop::Diff

Instance Method Details

#column(index, &block) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/chop/definition_list.rb', line 13

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

#field(key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/chop/definition_list.rb', line 22

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

#image(*cols) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/chop/definition_list.rb', line 33

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