Class: LinkOracle::Extractor::Body
- Inherits:
-
Object
- Object
- LinkOracle::Extractor::Body
- Defined in:
- lib/link_oracle/extractor/body.rb
Instance Attribute Summary collapse
-
#link_data ⇒ Object
readonly
Returns the value of attribute link_data.
-
#parsed_body ⇒ Object
readonly
Returns the value of attribute parsed_body.
Instance Method Summary collapse
- #descriptions ⇒ Object
- #images ⇒ Object
-
#initialize(parsed_body) ⇒ Body
constructor
A new instance of Body.
- #perform ⇒ Object
- #titles ⇒ Object
Constructor Details
Instance Attribute Details
#link_data ⇒ Object (readonly)
Returns the value of attribute link_data.
4 5 6 |
# File 'lib/link_oracle/extractor/body.rb', line 4 def link_data @link_data end |
#parsed_body ⇒ Object (readonly)
Returns the value of attribute parsed_body.
4 5 6 |
# File 'lib/link_oracle/extractor/body.rb', line 4 def parsed_body @parsed_body end |
Instance Method Details
#descriptions ⇒ Object
32 33 34 |
# File 'lib/link_oracle/extractor/body.rb', line 32 def descriptions @description ||= parsed_body.xpath("//p/text()").first(3).compact.map{ |text| text.content } end |
#images ⇒ Object
26 27 28 29 30 |
# File 'lib/link_oracle/extractor/body.rb', line 26 def images @images ||= parsed_body.xpath( "//img[@src[contains(.,'://') and not(contains(.,'ads.') or contains(.,'ad.') or contains(.,'?'))]]" ).first(3).compact.map{ |node| node['src'] } end |
#perform ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/link_oracle/extractor/body.rb', line 11 def perform link_data.assign({ titles: titles, image_urls: images, descriptions: descriptions }) end |
#titles ⇒ Object
20 21 22 23 24 |
# File 'lib/link_oracle/extractor/body.rb', line 20 def titles @titles ||= parsed_body.xpath( "//h1/text() | //h2/text() | //h3/text()" ).first(3).compact.map{ |text| text.content } end |