Class: InTheNews::Item
- Inherits:
-
Object
- Object
- InTheNews::Item
- Defined in:
- lib/inthenews.rb
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(element) ⇒ Item
constructor
A new instance of Item.
-
#remove_noprint_elements! ⇒ Object
Remove any child nodes with class “nopront”.
- #text ⇒ Object
-
#topics ⇒ Object
Rescursively search for all a elements in this element and return their value (removing /wiki/).
Constructor Details
#initialize(element) ⇒ Item
Returns a new instance of Item.
6 7 8 9 |
# File 'lib/inthenews.rb', line 6 def initialize(element) @element = element end |
Instance Method Details
#html ⇒ Object
23 24 25 |
# File 'lib/inthenews.rb', line 23 def html @element.inner_html end |
#remove_noprint_elements! ⇒ Object
Remove any child nodes with class “nopront”. This removes the boilerplate Wikinews, Obituries etc.
13 14 15 16 17 |
# File 'lib/inthenews.rb', line 13 def @element.xpath('//*[starts-with(@class,"noprint")]').each do |node| node.children.remove end end |
#text ⇒ Object
19 20 21 |
# File 'lib/inthenews.rb', line 19 def text @element.inner_text end |
#topics ⇒ Object
Rescursively search for all a elements in this element and return their value (removing /wiki/)
29 30 31 32 33 |
# File 'lib/inthenews.rb', line 29 def topics @element.xpath('.//a').map do |a| a.attr('href').gsub('/wiki/','') end end |