Sha256: 2a9e7f6dc60e3a7b78d234b6637c0fa0b94b812621524221ed707c4453c2f8b3

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

module RubyHackernews

  class EntryParser

    def initialize(first_line, second_line)
      @first_line  = first_line
      @second_line = second_line
    end

    def parse
      first_line_title = @first_line.search("[@class='title']")
      number_segment = nil
      link_segment = nil
      if(first_line_title.length > 1)
        number_segment = first_line_title[0]
        link_segment = first_line_title[1]
      else
        link_segment = first_line_title[0]
      end
      number   = number_segment.inner_html.sub(".","").to_i if number_segment
      link     = LinkInfoParser.new(link_segment).parse
      voting   = VotingInfoParser.new(@first_line.search("td/center/a"), @second_line.search("[@class='subtext']")[0]).parse
      user     = UserInfoParser.new(@second_line.search("[@class='subtext']")[0]).parse
      comments = CommentsInfoParser.new(@second_line.search("[@class='subtext']")[0]).parse
      time     = TimeInfoParser.new(@second_line.search("[@class='subtext']").children[3]).parse
      return Entry.new(number, link, voting, user, comments, time)
    end
    
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-hackernews-1.3.6 lib/ruby-hackernews/services/parsers/entry_parser.rb
ruby-hackernews-1.3.5 lib/ruby-hackernews/services/parsers/entry_parser.rb
ruby-hackernews-1.3.3 lib/ruby-hackernews/services/parsers/entry_parser.rb
ruby-hackernews-1.3.2 lib/ruby-hackernews/services/parsers/entry_parser.rb
ruby-hackernews-1.3.1 lib/ruby-hackernews/services/parsers/entry_parser.rb
ruby-hackernews-1.3.0 lib/ruby-hackernews/services/parsers/entry_parser.rb