class Scraperd::Activity

Public Class Methods

new(item) click to toggle source
Calls superclass method
# File lib/scraperd/activity.rb, line 8
def initialize(item)
  super(Hashie::Mash.new({
      id:         item[:guid].force_encoding("UTF-8"),
      title:      title_from_title(item[:title]),
      year:       year_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]
    })
  )      
end

Public Instance Methods

nicetitle_from_url(url) click to toggle source
# File lib/scraperd/activity.rb, line 22
def nicetitle_from_url(url)
  url.split('/').last
end
score_from_title(title) click to toggle source
# File lib/scraperd/activity.rb, line 45
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) click to toggle source
# File lib/scraperd/activity.rb, line 31
def title_from_title(title)
  title.split(' - ')[0..-2].join(' - ')
    .split(',')[0..-2].join(',')
    .strip
    .force_encoding("UTF-8")
end
watched_at_from_description(description) click to toggle source
# File lib/scraperd/activity.rb, line 26
def watched_at_from_description(description)
  string_date = description.match(/<p>Watched on (.*)<\/p>/)[1]
  Time.parse string_date
end
year_from_title(title) click to toggle source
# File lib/scraperd/activity.rb, line 38
def year_from_title(title)
  title.split(' - ')[0..-2].join(' - ')
    .split(',').last
    .strip
    .force_encoding("UTF-8")
end