Class: Result

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#allObject

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_countObject

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_dateObject

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

#authorObject

Attribute Accessors declared for each piece of information collected from each result



8
9
10
# File 'lib/askoverflow/result.rb', line 8

def author
  @author
end

#full_aObject

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_qObject

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

#idObject

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

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

#questionObject

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

#sampleObject

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

#tagsObject

Attribute Accessors declared for each piece of information collected from each result



8
9
10
# File 'lib/askoverflow/result.rb', line 8

def tags
  @tags
end

Class Method Details

.allObject

provides access to the @@all class variable



40
41
42
# File 'lib/askoverflow/result.rb', line 40

def self.all
    @@all
end

.clear_resultsObject

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