Class: Letteropend::Film

Inherits:
Object
  • Object
show all
Defined in:
lib/letteropend/film.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, url, callbacks = {}) ⇒ Film

Returns a new instance of Film.



7
8
9
10
11
12
# File 'lib/letteropend/film.rb', line 7

def initialize(title, url, callbacks={})
  @title = title
  @url = url
  @pulled = false
  @callbacks = callbacks
end

Instance Attribute Details

#overviewObject (readonly)

Returns the value of attribute overview.



6
7
8
# File 'lib/letteropend/film.rb', line 6

def overview
  @overview
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



6
7
8
# File 'lib/letteropend/film.rb', line 6

def runtime
  @runtime
end

#taglineObject (readonly)

Returns the value of attribute tagline.



6
7
8
# File 'lib/letteropend/film.rb', line 6

def tagline
  @tagline
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/letteropend/film.rb', line 6

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/letteropend/film.rb', line 6

def url
  @url
end

Instance Method Details

#==(film) ⇒ Object



63
64
65
# File 'lib/letteropend/film.rb', line 63

def ==(film)
  @title == film.title and @url == film.url
end

#pull_dataObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/letteropend/film.rb', line 35

def pull_data
  if @callbacks[:pulling_film]
    @callbacks[:pulling_film].call(self)
  end
  
  # pull the page from the url
  page = Nokogiri::HTML(open("http://www.letterboxd.com#{@url}"))
  @pulled = true
  
  # get the runtime for the film
  runtime_cap = page.css(".text-link").text.match(/(\d+) mins/)
  if runtime_cap
    @runtime = runtime_cap.captures[0].to_i
  else
    @runtime = 0
  end

  # get the tagline for the film
  @tagline = page.css(".tagline").text

  # get the overview for the film
  @overview = page.css("div.truncate").text.strip
  
  if @callbacks[:pulled_film]
    @callbacks[:pulled_film].call(self)
  end
end