Class: TellyReviews::Review

Inherits:
Object
  • Object
show all
Defined in:
lib/telly_reviews/review.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Review

Returns a new instance of Review.



6
7
8
9
10
11
# File 'lib/telly_reviews/review.rb', line 6

def initialize(hash={})
  hash.each do |k,v|
    self.send("#{k}=", v)
  end
  @@all << self
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



2
3
4
# File 'lib/telly_reviews/review.rb', line 2

def author
  @author
end

#author_twitterObject

Returns the value of attribute author_twitter.



2
3
4
# File 'lib/telly_reviews/review.rb', line 2

def author_twitter
  @author_twitter
end

#bodyObject

Returns the value of attribute body.



2
3
4
# File 'lib/telly_reviews/review.rb', line 2

def body
  @body
end

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/telly_reviews/review.rb', line 2

def date
  @date
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/telly_reviews/review.rb', line 2

def title
  @title
end

#urlObject

Returns the value of attribute url.



2
3
4
# File 'lib/telly_reviews/review.rb', line 2

def url
  @url
end

Class Method Details

.allObject



13
14
15
# File 'lib/telly_reviews/review.rb', line 13

def self.all
  @@all    
end

.find(index) ⇒ Object



25
26
27
# File 'lib/telly_reviews/review.rb', line 25

def self.find(index)
  self.all[index-1]
end

Instance Method Details

#review_detailsObject



17
18
19
20
21
22
23
# File 'lib/telly_reviews/review.rb', line 17

def review_details
  doc = Nokogiri::HTML(open(self.url))

  @date = doc.css(".article-body .abstract .timestamp").text
  @author_twitter = doc.css(".byline .author .url a").text
  @body = doc.css(".article-body .variety-content-wrapper").text.strip
end