class TildeScraper::Comment

Attributes

age[RW]
author[RW]
children[RW]
level[RW]
text[RW]
url[RW]
votes[RW]

Public Class Methods

all() click to toggle source
# File lib/tilde_scraper/comment.rb, line 60
def self.all
  @@all
end
all_top() click to toggle source
# File lib/tilde_scraper/comment.rb, line 56
def self.all_top
  @@all.select { |comment| comment.level == 0 }
end
create_from_array(array) click to toggle source
# File lib/tilde_scraper/comment.rb, line 13
def self.create_from_array(array)
  array.map do |comment_hash|
    comment = create(comment_hash.reject { |key, val| key == :children })
    comment.children = self.create_from_array(comment_hash[:children])
    comment
  end
end
display(array, indent = 0) click to toggle source
# File lib/tilde_scraper/comment.rb, line 49
def self.display(array, indent = 0)
  array.each do |comment|
    comment.display(indent)
    display(comment.children, indent + 1)
  end
end
display_page(url) click to toggle source
# File lib/tilde_scraper/comment.rb, line 45
def self.display_page(url)
  display(find_top_by_url(url))
end
find_by_url(url) click to toggle source
# File lib/tilde_scraper/comment.rb, line 21
def self.find_by_url(url)
  all.select { |comment| comment.url == url }
end
find_top_by_url(url) click to toggle source
# File lib/tilde_scraper/comment.rb, line 25
def self.find_top_by_url(url)
  all.select { |comment| comment.url == url && comment.level == 0}
end
new(attributes) click to toggle source
# File lib/tilde_scraper/comment.rb, line 9
def initialize(attributes)
  add_attributes(attributes.reject { |key, val| key == :children })
end

Public Instance Methods

display(indent = 0) click to toggle source
# File lib/tilde_scraper/comment.rb, line 29
def display(indent = 0)
  indent(indent)
  puts self.author
  display_text(indent)
  indent(indent)
  puts "Votes: " + self.votes if self.votes
  puts "-" * 10
end
display_text(indent = 0) click to toggle source
# File lib/tilde_scraper/comment.rb, line 38
def display_text(indent = 0)
  self.text.split("\n").each do |line|
    indent(indent)
    puts line
  end
end

Private Instance Methods

indent(n) click to toggle source
# File lib/tilde_scraper/comment.rb, line 65
def indent(n)
  print "\t" * n
end