module TableStepsHelper::ArrayMethods
Public Instance Methods
character(code)
click to toggle source
Only cross-Ruby way to get a character for its UTF-16 (hex) representation
# File lib/spreewald/table_steps.rb, line 30 def character(code) [code.to_i(16)].pack('U*') end
find_row(expected_row)
click to toggle source
# File lib/spreewald/table_steps.rb, line 9 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)
click to toggle source
# File lib/spreewald/table_steps.rb, line 34 def normalize_content(content) shy = character("00ad") # soft hyphen nbsp = character("00a0") # non-breaking space zwsp = character("200b") # zero-width space content = content.gsub(/[#{shy}#{zwsp}]/, '') content = content.gsub(/[\r\n\t#{nbsp}]+/, ' ') content = content.gsub(/ {2,}/, ' ') content = content.strip content end