Class: RubyHackernews::CommentsInfoParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-hackernews/services/parsers/comments_info_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(comments_element) ⇒ CommentsInfoParser

Returns a new instance of CommentsInfoParser.



5
6
7
# File 'lib/ruby-hackernews/services/parsers/comments_info_parser.rb', line 5

def initialize(comments_element)
  @element = comments_element.search("a")[1]
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
# File 'lib/ruby-hackernews/services/parsers/comments_info_parser.rb', line 9

def parse
  comments_info = nil
  if @element && @element['href'] =~ /id/
    comments      = @element.inner_html.split[0].to_i
    comments_page = @element['href']
    comments_info = CommentsInfo.new(comments, comments_page)
  end
  return comments_info
end