Module: TableStepsHelper::ArrayMethods

Defined in:
lib/spreewald/table_steps.rb

Instance Method Summary collapse

Instance Method Details

#find_row(expected_row) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spreewald/table_steps.rb', line 8

def find_row(expected_row)
  find_index do |row|
    expected_row.all? do |expected_column|
      first_column = row.find_index do |column|
        content = normalize_content(column.content)
        expected_content = normalize_content(expected_column)
        matching_parts = expected_content.split(/\s*\*\s*/, -1).collect { |part| Regexp.escape(part) }
        matching_expression = /\A#{matching_parts.join(".*")}\z/
        content =~ matching_expression
      end
      if first_column.nil?
        false
      else
        row = row[(first_column + 1)..-1]
        true
      end
    end
  end
end

#normalize_content(content) ⇒ Object



28
29
30
31
# File 'lib/spreewald/table_steps.rb', line 28

def normalize_content(content)
  nbsp = " "
  content.gsub(/[\r\n\t]+/, ' ').gsub(nbsp, ' ').gsub(/ {2,}/, ' ').strip
end