Class: PlayResult

Inherits:
Object
  • Object
show all
Defined in:
lib/google-play-class.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, title) ⇒ PlayResult

Returns a new instance of PlayResult.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/google-play-class.rb', line 7

def initialize(id,type,title)
	@id=id
	@type=type
	@title=title
	@price=""
	@rating=""
	@description=""
	@thumbnail=""
	@actors=Array.new
	@lengthtime=""
	@contentrating=""
	@genre=""
	@related=Array.new
	fillPlayData(id,type,title)
end

Instance Attribute Details

#actorsObject

Returns the value of attribute actors.



5
6
7
# File 'lib/google-play-class.rb', line 5

def actors
  @actors
end

#contentratingObject

Returns the value of attribute contentrating.



5
6
7
# File 'lib/google-play-class.rb', line 5

def contentrating
  @contentrating
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/google-play-class.rb', line 5

def description
  @description
end

#genreObject

Returns the value of attribute genre.



5
6
7
# File 'lib/google-play-class.rb', line 5

def genre
  @genre
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/google-play-class.rb', line 5

def id
  @id
end

#lengthtimeObject

Returns the value of attribute lengthtime.



5
6
7
# File 'lib/google-play-class.rb', line 5

def lengthtime
  @lengthtime
end

#priceObject

Returns the value of attribute price.



5
6
7
# File 'lib/google-play-class.rb', line 5

def price
  @price
end

#ratingObject

Returns the value of attribute rating.



5
6
7
# File 'lib/google-play-class.rb', line 5

def rating
  @rating
end

Returns the value of attribute related.



5
6
7
# File 'lib/google-play-class.rb', line 5

def related
  @related
end

#thumbnailObject

Returns the value of attribute thumbnail.



5
6
7
# File 'lib/google-play-class.rb', line 5

def thumbnail
  @thumbnail
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/google-play-class.rb', line 5

def title
  @title
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/google-play-class.rb', line 5

def type
  @type
end

Instance Method Details

#fillPlayData(id, type, title) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/google-play-class.rb', line 23

def fillPlayData(id,type,title)
	doc = Nokogiri::HTML(open("https://play.google.com/store/#{type}/details?id=#{id}"))
	get_price(doc)
	get_rating(doc)
	get_description(doc)
	get_thumbnail(doc)
	get_actors(doc)
	get_lengthtime(doc)
	get_contentrating(doc)
	get_genre(doc)
	get_related(doc)
end

#get_actors(doc) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/google-play-class.rb', line 64

def get_actors(doc)
	if doc.css('td.credit-cell span[itemprop=actors] a span').length != 0
		doc.css('td.credit-cell span[itemprop=actors] a span').each{ |value|
			@actors << value.text.to_s
		}
	end
end

#get_contentrating(doc) ⇒ Object



82
83
84
85
86
# File 'lib/google-play-class.rb', line 82

def get_contentrating(doc)
	if doc.css('dd[itemprop=contentRating]').length != 0
		@contentrating = doc.css('dd[itemprop=contentRating]').text
	end
end

#get_description(doc) ⇒ Object



52
53
54
55
56
# File 'lib/google-play-class.rb', line 52

def get_description(doc)
	if doc.css('div#doc-original-text').length != 0
		@description = doc.css('div#doc-original-text').text
	end
end

#get_genre(doc) ⇒ Object



88
89
90
91
92
# File 'lib/google-play-class.rb', line 88

def get_genre(doc)
	if doc.css('ul.doc-genres .doc-genre-link a:first-child').length != 0
		@genre = doc.css('ul.doc-genres .doc-genre-link a:first-child').text
	end
end

#get_lengthtime(doc) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/google-play-class.rb', line 72

def get_lengthtime(doc)
	if doc.css('dl.doc-metadata-list dd').length != 0
		doc.css('dl.doc-metadata-list dd').each{ |value|
			if value.text.to_s =~ /minutes/
				@lengthtime = value.text.to_s
			end
		}
	end
end

#get_price(doc) ⇒ Object



40
41
42
43
44
# File 'lib/google-play-class.rb', line 40

def get_price(doc)
	if doc.css('.buy-wrapper .buy-border a.buy-link .buy-button-price').length != 0
		@price = doc.css('.buy-wrapper .buy-border a.buy-link .buy-button-price')[0].text
	end
end

#get_rating(doc) ⇒ Object



46
47
48
49
50
# File 'lib/google-play-class.rb', line 46

def get_rating(doc)
	if doc.css('.doc-details-ratings-price div div.ratings').length != 0
		@rating = doc.css('.doc-details-ratings-price div div.ratings')[0]['title']
	end
end


94
95
96
97
98
99
100
# File 'lib/google-play-class.rb', line 94

def get_related(doc)
	if doc.css('div#related-list ul.snippet-list li div div.details a.title').length != 0
		doc.css('div#related-list ul.snippet-list li div div.details a.title').each{ |value|
			@related << value.text.to_s
		}
	end
end

#get_thumbnail(doc) ⇒ Object



58
59
60
61
62
# File 'lib/google-play-class.rb', line 58

def get_thumbnail(doc)
	if doc.css('div.doc-banner-icon img').length != 0
		@thumbnail = doc.css('div.doc-banner-icon img')[0]['src']
	end
end

#get_title(doc) ⇒ Object



35
36
37
38
39
# File 'lib/google-play-class.rb', line 35

def get_title(doc)
	if @title == ""
		@title = doc.css('div.doc-header-content h1.doc-header-title').text
	end
end