Class: RubyHackernews::VotingInfoParser

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

Instance Method Summary collapse

Constructor Details

#initialize(voting_element, score_element) ⇒ VotingInfoParser

Returns a new instance of VotingInfoParser.



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

def initialize(voting_element, score_element)
  @voting_element   = voting_element
  @score_element    = score_element
end

Instance Method Details

#parseObject



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

def parse
  upvote   = @voting_element[0]['href'] if @voting_element[0]
  downvote = @voting_element[1]['href'] if @voting_element[1]
  points_element = @score_element.search("span")[0]
  score    = points_element.inner_html.split[0].to_i if points_element
  return VotingInfo.new(score, upvote, downvote)
end