Class: ScraperGooglePlay::App

Inherits:
Base
  • Object
show all
Defined in:
lib/scraper_google_play/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#exist?, #list_packname_with_page

Constructor Details

#initialize(package_name, options = {}) ⇒ App

Returns a new instance of App.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/scraper_google_play/app.rb', line 6

def initialize(package_name, options = {})
  
  @package_name = package_name
  @agent = Mechanize.new
@query = {
  id: package_name,
}.merge(options).to_query

unless exist?("#{ScraperGooglePlay::APPURL}?#{@query}")
  @page = nil
else 
  @page = @agent.get("#{ScraperGooglePlay::APPURL}?#{@query}")
end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def address
  @address
end

#android_versionObject

Returns the value of attribute android_version.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def android_version
  @android_version
end

#android_version_textObject

Returns the value of attribute android_version_text.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def android_version_text
  @android_version_text
end

#app_nameObject

Returns the value of attribute app_name.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def app_name
  @app_name
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def description
  @description
end

#developerObject

Returns the value of attribute developer.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def developer
  @developer
end

#emailObject

Returns the value of attribute email.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def email
  @email
end

#genre_idObject

Returns the value of attribute genre_id.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def genre_id
  @genre_id
end

#genre_textObject

Returns the value of attribute genre_text.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def genre_text
  @genre_text
end

#package_nameObject

Returns the value of attribute package_name.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def package_name
  @package_name
end

#scoreObject

Returns the value of attribute score.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def score
  @score
end

#screen_shots=(value) ⇒ Object

Sets the attribute screen_shots

Parameters:

  • value

    the value to set the attribute screen_shots to.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def screen_shots=(value)
  @screen_shots = value
end

#sizeObject

Returns the value of attribute size.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def size
  @size
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def title
  @title
end

#versionObject

Returns the value of attribute version.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def version
  @version
end

#videObject

Returns the value of attribute vide.



2
3
4
# File 'lib/scraper_google_play/app.rb', line 2

def vide
  @vide
end

Instance Method Details

#infoObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scraper_google_play/app.rb', line 21

def info
  return {} unless @page
  detailsInfo = @page.at('.details-info')
additionalInfo = @page.search('.details-section-contents')

mainGenre = detailsInfo.at('.category')

android_version_text = @page.at('.details-section-contents div.content[itemprop="operatingSystems"]').text().strip()
@app_info = {
  name: name,
  logo: ,
  screen_shots: screen_shots,
  developer: detailsInfo.at('span[itemprop="name"]').text,
  address: @page.at('.content.physical-address').try(:text),
  email: @page.at('.content.contains-text-link .dev-link[href^="mailto:"]') ? @page.at('.content.contains-text-link .dev-link[href^="mailto:"]').attr('href').split(':')[-1] : nil , 
  title: detailsInfo.at('.document-title').text.strip,
  genre_text: mainGenre.text().strip,
  genre_id: mainGenre.attr('href').split('/')[4],
  version: @page.at('.details-section-contents div.content[itemprop="softwareVersion"]') ? @page.at('.details-section-contents div.content[itemprop="softwareVersion"]').text().strip() : nil,
  description: @page.at('.details-section-contents div[itemprop=description] div').text().gsub(/<\/p>/, '\n</p>'),
  android_version_text: android_version_text,
  android_version: normalizeAndroidVersion(android_version_text),
  contentRating: @page.at('.details-section-contents div.content[itemprop="contentRating"]').text().strip(),
  size: @page.at('.details-section-contents div.content[itemprop="fileSize"]').try(:text),
  video: @page.at('.screenshots span.preview-overlay-container[data-video-url]') ? @page.at('.screenshots span.preview-overlay-container[data-video-url]').attr('data-video-url') : nil,
  score: @page.at('.rating-box div.score').text().to_s.gsub(',', '.'),

}   
end

#similar_appObject



51
52
53
54
55
56
57
58
59
# File 'lib/scraper_google_play/app.rb', line 51

def similar_app
  return nil unless @page
  apps = []
  recommendation = @page.at(".recommendation")
  recommendation.search(".cards id-card-list .card.apps").each do |app|
    apps <<  app.attr('data-docid')
  end
  apps
end