google_movies 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
  $:.unshift File.expand_path('../models', __FILE__)
3
3
  require 'nokogiri'
4
4
  require "net/http"
@@ -7,15 +7,23 @@ require 'movie'
7
7
  require 'movie_theater'
8
8
 
9
9
  module HttpCapture
10
-
10
+
11
11
  def movies_theaters(page_url)
12
12
  @http_address = URI.parse(URI.encode(page_url.strip))
13
- get_information(@http_address)
14
- end
15
-
16
- def get_information(url)
17
- @movies_theater = []
18
13
  @doc = page_doc(@http_address)
14
+ pages = @doc.css('div.n a[@href]')
15
+ pages.each do |p|
16
+ http_address = URI.parse(URI.encode("http://google.com#{p.values.first.strip}"))
17
+ doc = page_doc(http_address)
18
+ get_information(doc)
19
+ end
20
+ @movies_theater
21
+ end
22
+
23
+ def get_information(doc)
24
+ @doc = doc
25
+ @movies_theater ||= []
26
+
19
27
  @doc.search('div[@class="theater"]').each do |theater|
20
28
  movies = []
21
29
  movies = get_movies(theater)
@@ -23,43 +31,52 @@ module HttpCapture
23
31
  end
24
32
  @movies_theater
25
33
  end
26
-
27
- private
28
-
34
+
35
+ private
36
+
29
37
  def page_doc(uri)
30
38
  Nokogiri::HTML(Net::HTTP.get_response(uri).body)
31
39
  end
32
40
 
33
- def create_movie_theater_with(theater, movies)
34
- id = theater.search('div[@class="desc"]').first.attr("id").gsub("theater_", "")
35
- name = theater.search('h2[@class="name"]').first.content
36
- info = theater.search('div[@class="info"]').first.content
37
- GoogleMovies::MovieTheater.new(name, info, id, movies)
38
- end
39
-
40
- def create_movie_with(movie)
41
- name = movie.search('div[@class="name"]').first.search('a').first.content
42
- id = movie.search('div[@class="name"]').first.search('a').first.attr("href").split("&mid=")[1]
43
- GoogleMovies::Movie.new(name, id)
44
- end
45
-
41
+ def create_movie_theater_with(theater, movies)
42
+ id = theater.search('div[@class="desc"]').first.attr("id").gsub("theater_", "")
43
+ name = theater.search('h2[@class="name"]').first.content
44
+ info = theater.search('div[@class="info"]').first.content
45
+ GoogleMovies::MovieTheater.new(name, info, id, movies)
46
+ end
47
+
48
+ def create_movie_with(movie)
49
+ name = movie.search('div[@class="name"]').first.search('a').first.content
50
+ id = movie.search('div[@class="name"]').first.search('a').first.attr("href").split("&mid=")[1]
51
+ info = movie.search('span[@class="info"]').first.content
52
+ times = get_movies_times(movie)
53
+ GoogleMovies::Movie.new(name, id, info, times)
54
+ end
55
+
56
+ def get_movies_times(movie)
57
+ times = ""
58
+ movie.css(".times").each do |time|
59
+ times << time.children.first.text
60
+ end
61
+ end
62
+
46
63
  def get_movies(theater)
47
64
  movies = []
48
65
  theater.search('div[@class="movie"]').each do |movie_document|
49
66
  movies << create_movie_with(movie_document)
50
67
  end
51
68
  movies
52
- end
53
-
69
+ end
70
+
54
71
  class Client
55
72
  include HttpCapture
56
-
73
+
57
74
  attr_accessor :movies_theater
58
-
75
+
59
76
  def initialize(page_url)
60
77
  @movies_theater = movies_theaters(page_url)
61
78
  end
62
-
79
+
63
80
  end
64
81
  end
65
82
 
@@ -1,11 +1,13 @@
1
1
  module GoogleMovies
2
2
  class Movie
3
-
4
- attr_accessor :name, :id
5
-
6
- def initialize(name, id)
3
+
4
+ attr_accessor :name, :id, :information, :times
5
+
6
+ def initialize(name, id, information, times)
7
7
  @name = name
8
8
  @id = id
9
+ @information = information
10
+ @times = times
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module GoogleMovies
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_movies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec