Class: Juknife::Scraping::Context
- Inherits:
-
Object
- Object
- Juknife::Scraping::Context
- Defined in:
- lib/juknife/scraping/context.rb
Overview
A context object keeps a state of scraping.
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #find(selector) ⇒ Object
- #find_all(selector) ⇒ Object
-
#initialize(node, result = {}) ⇒ Context
constructor
A new instance of Context.
- #text(selector) ⇒ Object
Constructor Details
#initialize(node, result = {}) ⇒ Context
Returns a new instance of Context.
9 10 11 12 |
# File 'lib/juknife/scraping/context.rb', line 9 def initialize(node, result = {}) @node = node @result = result end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
7 8 9 |
# File 'lib/juknife/scraping/context.rb', line 7 def node @node end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/juknife/scraping/context.rb', line 7 def result @result end |
Instance Method Details
#find(selector) ⇒ Object
14 15 16 |
# File 'lib/juknife/scraping/context.rb', line 14 def find(selector) node.at_css(selector) end |
#find_all(selector) ⇒ Object
18 19 20 |
# File 'lib/juknife/scraping/context.rb', line 18 def find_all(selector) node.css(selector) end |
#text(selector) ⇒ Object
22 23 24 |
# File 'lib/juknife/scraping/context.rb', line 22 def text(selector) find(selector)&.text&.strip&.gsub(/(\s)(\s*)/, '\1') end |