Class: RubyHackernews::VotingInfoParser
- Inherits:
-
Object
- Object
- RubyHackernews::VotingInfoParser
- Defined in:
- lib/ruby-hackernews/services/parsers/voting_info_parser.rb
Instance Method Summary collapse
-
#initialize(voting_element, score_element) ⇒ VotingInfoParser
constructor
A new instance of VotingInfoParser.
- #parse ⇒ Object
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
#parse ⇒ Object
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 |