class Strigil::CommentsParser

Public Class Methods

parse(client) click to toggle source
# File lib/strigil/comments_parser.rb, line 3
def self.parse(client)
  comments = get_comments(client)

  comments.map do |comment|
    Strigil::Comment.new(
      author: get_author(comment),
      subreddit: get_subreddit(comment),
      permalink: get_permalink(comment),
      timestamp: get_timestamp(comment),
      text: get_text(comment)
    )
  end
end

Private Class Methods

get_author(comment) click to toggle source
# File lib/strigil/comments_parser.rb, line 23
def self.get_author(comment)
  comment.attribute("data-author")
end
get_comments(client) click to toggle source
# File lib/strigil/comments_parser.rb, line 19
def self.get_comments(client)
  client.find_elements(class: "comment")
end
get_entry(comment) click to toggle source
# File lib/strigil/comments_parser.rb, line 43
def self.get_entry(comment)
  comment.find_element(class: "entry")
end
get_subreddit(comment) click to toggle source
# File lib/strigil/comments_parser.rb, line 27
def self.get_subreddit(comment)
  comment.attribute("data-subreddit")
end
get_text(comment) click to toggle source
# File lib/strigil/comments_parser.rb, line 39
def self.get_text(comment)
  get_entry(comment).find_element(class: "usertext-body").text
end
get_timestamp(comment) click to toggle source
# File lib/strigil/comments_parser.rb, line 35
def self.get_timestamp(comment)
  get_entry(comment).find_element(tag_name: "time").attribute(:title)
end