Class: TheData
- Inherits:
-
Object
- Object
- TheData
- Defined in:
- lib/theData.rb
Instance Attribute Summary collapse
-
#all_categories ⇒ Object
Returns the value of attribute all_categories.
-
#category ⇒ Object
Returns the value of attribute category.
-
#category_link ⇒ Object
Returns the value of attribute category_link.
-
#post ⇒ Object
Returns the value of attribute post.
Instance Method Summary collapse
- #add_post_attributes(selection) ⇒ Object
- #get_categories ⇒ Object
- #get_selected_category ⇒ Object
-
#initialize ⇒ TheData
constructor
A new instance of TheData.
- #select_category(selection) ⇒ Object
- #select_specific_post(selection) ⇒ Object
Constructor Details
#initialize ⇒ TheData
Returns a new instance of TheData.
4 5 6 7 |
# File 'lib/theData.rb', line 4 def initialize @post = {} get_categories end |
Instance Attribute Details
#all_categories ⇒ Object
Returns the value of attribute all_categories.
2 3 4 |
# File 'lib/theData.rb', line 2 def all_categories @all_categories end |
#category ⇒ Object
Returns the value of attribute category.
2 3 4 |
# File 'lib/theData.rb', line 2 def category @category end |
#category_link ⇒ Object
Returns the value of attribute category_link.
2 3 4 |
# File 'lib/theData.rb', line 2 def category_link @category_link end |
#post ⇒ Object
Returns the value of attribute post.
2 3 4 |
# File 'lib/theData.rb', line 2 def post @post end |
Instance Method Details
#add_post_attributes(selection) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
9 10 11 12 13 14 |
# 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 ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
16 17 18 19 |
# File 'lib/theData.rb', line 16 def select_category(selection) puts "category = #{selection[:link]}" @category_link = selection[:link] end |
#select_specific_post(selection) ⇒ Object
27 28 29 |
# File 'lib/theData.rb', line 27 def select_specific_post(selection) add_post_attributes(selection) end |