Class: Scrapperd::Activity

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/scrapperd/activity.rb

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Activity

Returns a new instance of Activity.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/scrapperd/activity.rb', line 8

def initialize(item)
  super(Hashie::Mash.new({
      title:              title_from_title(item[:title]),
      score:              score_from_title(item[:title]),
      link:               item[:link].force_encoding("UTF-8"),
      film_link:          "http://letterboxd.com/film/#{nicetitle_from_url(item[:link])}/".force_encoding("UTF-8"),
      watched_at:         watched_at_from_description(item[:description]),
      added_at:           item[:pubDate],
      original_response:  item
    })
  )      
end

Instance Method Details

#nicetitle_from_url(url) ⇒ Object



21
22
23
# File 'lib/scrapperd/activity.rb', line 21

def nicetitle_from_url(url)
  url.split('/').last
end

#score_from_title(title) ⇒ Object



34
35
36
37
38
# File 'lib/scrapperd/activity.rb', line 34

def score_from_title(title)
  html_score = title.split(' - ').last
  html_score.force_encoding("UTF-8")
  html_score.split(//).map{|ind_score| ind_score == "" ? 2 : 1 }.inject{|sum,x| sum + x }
end

#title_from_title(title) ⇒ Object



30
31
32
# File 'lib/scrapperd/activity.rb', line 30

def title_from_title(title)
  title.split(' - ')[0..-2].join(' - ').force_encoding("UTF-8")
end

#watched_at_from_description(description) ⇒ Object



25
26
27
28
# File 'lib/scrapperd/activity.rb', line 25

def watched_at_from_description(description)
  string_date = description.match(/<p>Watched on (.*)<\/p>/)[1]
  Time.parse string_date
end