Class: Wfstatus::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html, config) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
10
# File 'lib/wfstatus/parser.rb', line 6

def initialize(html, config)
  @html = html
  @config = config
  @page = Nokogiri::HTML(@html)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



5
6
7
# File 'lib/wfstatus/parser.rb', line 5

def html
  @html
end

#pageObject (readonly)

Returns the value of attribute page.



5
6
7
# File 'lib/wfstatus/parser.rb', line 5

def page
  @page
end

Instance Method Details

#messagesObject



12
13
14
# File 'lib/wfstatus/parser.rb', line 12

def messages
  @messages ||= parse
end

#parseObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wfstatus/parser.rb', line 16

def parse
  messages = []
  posts.each do |p|
    posted = p.at_css('div.entry-date abbr').attributes['title']
    message = p.at_css('div.entry-content').text
    title_link = p.at_css('.entry-title a')
    url = title_link.attributes['href']
    title = title_link.text
    messages << Wfmessage.new(posted, title, message, url, @config)
  end
  messages
end

#postsObject



29
30
31
# File 'lib/wfstatus/parser.rb', line 29

def posts
  @posts ||= @page.css('div.post')
end