Class: Result
- Inherits:
-
Object
- Object
- Result
- Defined in:
- lib/askoverflow/result.rb
Overview
This is a class used to store the data of each scraped result in a central, easy to access location
Constant Summary collapse
- @@all =
class varible array used to store each result instance
Array.new
Instance Attribute Summary collapse
-
#all ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#answer_count ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#ask_date ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#author ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#full_a ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#full_q ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#id ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#link ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#question ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#sample ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
-
#tags ⇒ Object
Attribute Accessors declared for each piece of information collected from each result.
Class Method Summary collapse
-
.all ⇒ Object
provides access to the @@all class variable.
-
.clear_results ⇒ Object
deletes all existing Result instances used when additional searches are performed.
-
.find_by_id(id) ⇒ Object
allows the user to access the results via human friendly indexing ie 1->10 not 0->9.
Instance Method Summary collapse
-
#add_full(content_hash) ⇒ Object
allows a result’s scraped full Q&A to be added to the instance.
-
#initialize(attributes) ⇒ Result
constructor
uses metaprogramming and attribut accessors to assign the values of an initial hash to the instance’s attributes, then shovels the instance onto @@all.
Constructor Details
#initialize(attributes) ⇒ Result
uses metaprogramming and attribut accessors to assign the values of an initial hash to the instance’s attributes, then shovels the instance onto @@all
16 17 18 19 20 21 |
# File 'lib/askoverflow/result.rb', line 16 def initialize(attributes) attributes.each do |s, v| self.send("#{s}=", v) end @@all << self end |
Instance Attribute Details
#all ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def all @all end |
#answer_count ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def answer_count @answer_count end |
#ask_date ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def ask_date @ask_date end |
#author ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def @author end |
#full_a ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def full_a @full_a end |
#full_q ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def full_q @full_q end |
#id ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def id @id end |
#link ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def link @link end |
#question ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def question @question end |
#sample ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def sample @sample end |
#tags ⇒ Object
Attribute Accessors declared for each piece of information collected from each result
8 9 10 |
# File 'lib/askoverflow/result.rb', line 8 def @tags end |
Class Method Details
.all ⇒ Object
provides access to the @@all class variable
40 41 42 |
# File 'lib/askoverflow/result.rb', line 40 def self.all @@all end |
.clear_results ⇒ Object
deletes all existing Result instances used when additional searches are performed
36 37 38 |
# File 'lib/askoverflow/result.rb', line 36 def self.clear_results @@all.clear end |
.find_by_id(id) ⇒ Object
allows the user to access the results via human friendly indexing ie 1->10 not 0->9
24 25 26 |
# File 'lib/askoverflow/result.rb', line 24 def self.find_by_id(id) @@all[id.to_i - 1] end |
Instance Method Details
#add_full(content_hash) ⇒ Object
allows a result’s scraped full Q&A to be added to the instance
29 30 31 32 33 |
# File 'lib/askoverflow/result.rb', line 29 def add_full(content_hash) content_hash.each do |s, v| self.send("#{s}=", v) end end |