Class: Nukitori::SchemaExtractor
- Inherits:
-
Object
- Object
- Nukitori::SchemaExtractor
- Defined in:
- lib/nukitori/schema_extractor.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#extract(html) ⇒ Hash
Extract data from HTML using the XPath schema.
-
#initialize(schema) ⇒ SchemaExtractor
constructor
A new instance of SchemaExtractor.
Constructor Details
#initialize(schema) ⇒ SchemaExtractor
Returns a new instance of SchemaExtractor.
8 9 10 |
# File 'lib/nukitori/schema_extractor.rb', line 8 def initialize(schema) @schema = deep_stringify_keys(schema) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/nukitori/schema_extractor.rb', line 5 def schema @schema end |
Instance Method Details
#extract(html) ⇒ Hash
Extract data from HTML using the XPath schema
15 16 17 18 |
# File 'lib/nukitori/schema_extractor.rb', line 15 def extract(html) doc = html.is_a?(Nokogiri::HTML::Document) ? html : Nokogiri::HTML(html) extract_fields(doc, schema) end |