Class: InTheNews::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/inthenews.rb

Instance Method Summary collapse

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
  remove_noprint_elements!
end

Instance Method Details

#htmlObject



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 remove_noprint_elements!
  @element.xpath('//*[starts-with(@class,"noprint")]').each do |node|
    node.children.remove
  end
end

#textObject



19
20
21
# File 'lib/inthenews.rb', line 19

def text
  @element.inner_text
end

#topicsObject

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