Class: Allocine::Show

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, debug = false) ⇒ Show

Returns a new instance of Show.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/allocine/show.rb', line 29

def initialize(id, debug=false)
  #TODO : New Regex for new version.    
  regexps = {
    :title => '<title>(.*?)<\/title>',
    :created_by => '<h4>Série créée par <a .*?>(.*?)</a>', 
    :producters => '<h4>Producteurs : (.*?)</h4>', 
    :nat => '<span style=\'font-weight:bold\'>Nationalité</span> : (.*?)</h5>', 
    :genres => '<span style=\'font-weight:bold\'>Genre</span> : (.*?)&nbsp;&nbsp;', 
    :duree => '<span style=\'font-weight:bold\'>Format</span> : (.+?).&nbsp;', 
    :original_title => '<h4><b>Titre original : </b></h4><h4 style="color:#D20000"><b>(.*?)</b></h4>',
    :actors => '<h4>Avec : (.*?)&nbsp;&nbsp;', 
    :synopsis => '<h5><span style=\'font-weight:bold\'>Synopsis</span>&nbsp;&nbsp;&nbsp;.*?<br />(.*?)</h5>',
    :image => '<td><div id=\'divM\' .*?><img src=\'(.*?)\' style=\'border:1px solid black;.*?>',
  }
  data = Allocine::Web.new(SHOW_DETAIL_URL % id).data.gsub(/\r|\n|\t/,"")
  regexps.each do |reg|
    print "#{reg[0]}: " if debug
    r = data.scan Regexp.new(reg[1], Regexp::MULTILINE)
    r = r.first.to_s.strip
    r.gsub!(' - AlloCiné', '')
    r.gsub!(/<.*?>/, '')
    self.instance_variable_set("@#{reg[0]}", r)
    print "#{r}\n" if debug
  end
end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



3
4
5
# File 'lib/allocine/show.rb', line 3

def actors
  @actors
end

#created_byObject

Returns the value of attribute created_by.



3
4
5
# File 'lib/allocine/show.rb', line 3

def created_by
  @created_by
end

#dureeObject

Returns the value of attribute duree.



3
4
5
# File 'lib/allocine/show.rb', line 3

def duree
  @duree
end

#genresObject

Returns the value of attribute genres.



3
4
5
# File 'lib/allocine/show.rb', line 3

def genres
  @genres
end

#imageObject

Returns the value of attribute image.



3
4
5
# File 'lib/allocine/show.rb', line 3

def image
  @image
end

#natObject

Returns the value of attribute nat.



3
4
5
# File 'lib/allocine/show.rb', line 3

def nat
  @nat
end

#original_titleObject

Returns the value of attribute original_title.



3
4
5
# File 'lib/allocine/show.rb', line 3

def original_title
  @original_title
end

#productersObject

Returns the value of attribute producters.



3
4
5
# File 'lib/allocine/show.rb', line 3

def producters
  @producters
end

#synopsisObject

Returns the value of attribute synopsis.



3
4
5
# File 'lib/allocine/show.rb', line 3

def synopsis
  @synopsis
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/allocine/show.rb', line 3

def title
  @title
end

Class Method Details

.find(search) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/allocine/show.rb', line 5

def self.find(search)
  search.gsub!(' ', '+')
  str = Allocine::Web.new(SHOW_SEARCH_URL % search).data
  shows = {}
  while str =~ /<a href='\/series\/ficheserie_gen_cserie=(\d+).html'>(.*?)<\/a>/mi
    id, name = $1, $2
    unless name =~ /<img(.*?)/
      str.gsub!("<a href=\'/series/ficheserie_gen_cserie=#{id}.html\'>#{name}</a>", "")
      name.gsub!(/<(.+?)>/,'')
      name.strip!
      shows[id] = name
    else
      str.gsub!("<a href=\'/series/ficheserie_gen_cserie=#{id}.html\'>#{name}</a>", "")
    end
  end
  
  shows
end

.lucky_find(search) ⇒ Object



24
25
26
27
# File 'lib/allocine/show.rb', line 24

def self.lucky_find(search)
  results = find(search)
  new(results.first)
end