Module: RemoteTable::Html
- Defined in:
- lib/remote_table/file/html.rb
Instance Method Summary collapse
Instance Method Details
#each_row(&block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/remote_table/file/html.rb', line 3 def each_row(&block) backup_file! convert_file_to_utf8! html_headers = (headers.is_a?(Array)) ? headers : nil Nokogiri::HTML(unescaped_html_without_soft_hyphens, nil, 'UTF-8').xpath(row_xpath).each do |row| values = row.xpath(column_xpath).map { |td| td.content.gsub(/\s+/, ' ').strip } if html_headers.nil? html_headers = values next end hash = zip html_headers, values yield hash if keep_blank_rows or hash.any? { |k, v| v.present? } end ensure restore_file! end |