Class: Daru::IO::Importers::HTML
- Defined in:
- lib/daru/io/importers/html.rb
Overview
Note:
Please note that this module works only for static table elements on a HTML page, and won't work in cases where the data is being loaded into the HTML table by inline Javascript.
HTML Importer Class, that extends read_html
method to Daru::DataFrame
Class Method Summary collapse
-
.read(path) ⇒ Daru::IO::Importers::HTML
Reads from a html file / website.
Instance Method Summary collapse
-
#call(match: nil, order: nil, index: nil, name: nil) ⇒ Array<Daru::DataFrame>
Imports Array of
Daru::DataFrame
s from a HTML Importer instance. -
#initialize ⇒ HTML
constructor
Checks for required gem dependencies of HTML Importer.
-
#read(path) ⇒ Daru::IO::Importers::HTML
Reads from a html file / website.
Methods inherited from Base
Methods inherited from Base
Constructor Details
#initialize ⇒ HTML
Checks for required gem dependencies of HTML Importer
16 17 18 19 |
# File 'lib/daru/io/importers/html.rb', line 16 def initialize require 'open-uri' optional_gem 'nokogiri' end |
Class Method Details
.read(path) ⇒ Daru::IO::Importers::HTML
Reads from a html file / website
32 33 34 35 |
# File 'lib/daru/io/importers/html.rb', line 32 def read(path) @file_data = Nokogiri.parse(open(path).read) self end |
Instance Method Details
#call(match: nil, order: nil, index: nil, name: nil) ⇒ Array<Daru::DataFrame>
Imports Array of Daru::DataFrame
s from a HTML Importer instance
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/daru/io/importers/html.rb', line 75 def call(match: nil, order: nil, index: nil, name: nil) @match = match @options = {name: name, index: index, order: order} @file_data .search('table') .map { |table| parse_table(table) } .compact .keep_if { |table| satisfy_dimension(table) && search(table) } .map { |table| decide_values(table, @options) } .map { |table| table_to_dataframe(table) } end |
#read(path) ⇒ Daru::IO::Importers::HTML
Reads from a html file / website
32 33 34 35 |
# File 'lib/daru/io/importers/html.rb', line 32 def read(path) @file_data = Nokogiri.parse(open(path).read) self end |