class TheData

Attributes

all_categories[RW]
category[RW]
post[RW]

Public Class Methods

new() click to toggle source
# File lib/theData.rb, line 4
def initialize
  @post = {}
  get_categories
end

Public Instance Methods

add_post_attributes(selection) click to toggle source
# File lib/theData.rb, line 31
def add_post_attributes(selection)
  selection = selection[:post]
  @post[:title] = selection.css('a.title').text
  @post[:author] = selection.css('a.author').text
  @post[:link] = selection.css('a.title')[0]['href']
  @post[:time] = "#{selection.css('time')[0]['title']}; #{selection.css('time')[0].inner_text}"

  if @post[:link][0] == '/'
    @post[:link] = "https://reddit.com" + @post[:link]
  end
end
get_categories() click to toggle source
# File lib/theData.rb, line 9
def get_categories
  @all_categories = Scraper.scrape_categories.collect do |category|
    next if category.text == 'wiki' or category.text == 'gilded' or category.text == 'promoted'
    {:name => category.text, :link => category['href']}
  end.compact
end
get_selected_category() click to toggle source
# File lib/theData.rb, line 21
def get_selected_category
  @category = Scraper.scrape_selected_category(@category_link).collect do |post|
    {:name => post.css('div.entry').inner_text.split('submitted')[0], :post => post}
  end
end
select_category(selection) click to toggle source
# File lib/theData.rb, line 16
def select_category(selection)
  puts "category = #{selection[:link]}"
  @category_link = selection[:link]
end
select_specific_post(selection) click to toggle source
# File lib/theData.rb, line 27
def select_specific_post(selection)
  add_post_attributes(selection)
end