play_scrape 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db0c57695c095a230aa69247d7c7304ace70d017
4
- data.tar.gz: 70f62dd285d7fce07e36b85028e0e1badf97bd0d
3
+ metadata.gz: 844f04d88029421e7499a1c914da1491423fc2f1
4
+ data.tar.gz: f68d3bfd9eba21b1ea0e04ab083fbd9e279ba226
5
5
  SHA512:
6
- metadata.gz: 35a2c4bd003c261a2f74dde1f63ee9725b04771effcbb5d83a02cdcf5aa3f2ff716dc32695c961f28b2a6883d7e956e8bc9c384199880449f08686a44b78aed0
7
- data.tar.gz: 86d82509d3c818026f311b0f1f21ee7a8678d59dd79ef41c26f72261c6b76a740323bd7fcb7e2de1a50e8d68d88f83210073f9e0b3dd3bf53a63c9208e06afef
6
+ metadata.gz: a2403b6fca41c3b618e5ef5cfae38382870894cd360ad2e1a914676668ed4b50690c0e89ef31a551f421ca91cf4a16512be4210808acf79f5f7086c9606222d1
7
+ data.tar.gz: 4d583fc3334542736a4752cf952d7c6eecc4b6052e25f45a3fc419dd2d5cdf938fabf73d1305d6afe6f347bf667e3b8fcbeba27fc3080a95cdbf717125f18924
@@ -1,7 +1,18 @@
1
1
  module PlayScrape
2
2
  class AppInfo
3
- attr_accessor :app_name, :package_name, :description, :rating, :num_ratings, :dev_url, :icon_url,
4
- :min_installs, :max_installs
3
+ ATTRIBUTES = [
4
+ :app_name,
5
+ :package_name,
6
+ :description,
7
+ :rating,
8
+ :num_ratings,
9
+ :dev_url,
10
+ :icon_url,
11
+ :min_installs,
12
+ :max_installs,
13
+ :version
14
+ ]
15
+ attr_accessor *ATTRIBUTES
5
16
 
6
17
  def initialize
7
18
  end
@@ -1,3 +1,3 @@
1
1
  module PlayScrape
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/play_scrape.rb CHANGED
@@ -13,8 +13,12 @@ module PlayScrape
13
13
  APP_RATING_CSS_PATH = 'div.score'
14
14
  APP_NUM_RATINGS_CSS_PATH = 'span.reviews-num'
15
15
  APP_DEV_URL_CSS_PATH = 'a.dev-link'
16
- APP_INSTALL_CSS_PATH = 'div.details-section div.details-section-contents div.meta-info div.content'
17
16
  APP_NAME_CSS_PATH = 'div.details-wrapper div.details-info div.info-container div.document-title div'
17
+ APP_ADDITIONAL_INFO_CSS_PATH = 'div.details-section div.details-section-contents div.meta-info div.content'
18
+
19
+ VERSION_REGEX = /\d\.\d(\.\d)?/
20
+ URL_REGEX = /q=(https?:\/\/[\S]+?)&/
21
+ INSTALLS_REGEX = /\d+ - \d+/
18
22
 
19
23
 
20
24
  # Returns @app_info of AppInfo class
@@ -31,13 +35,15 @@ module PlayScrape
31
35
  icon_url = html.css(APP_ICON_CSS_PATH).first
32
36
 
33
37
  # A bit hacky below but it'll do
34
- installs = html.css(APP_INSTALL_CSS_PATH)[2].text.gsub(",", "").split("-").map(&:to_i)
38
+ installs_text = html.css(APP_ADDITIONAL_INFO_CSS_PATH)[2].text.strip
39
+ installs = installs_text.gsub(",", "").split("-").map(&:to_i) if installs_text.match(INSTALLS_REGEX)
40
+ version_text = html.css(APP_ADDITIONAL_INFO_CSS_PATH)[3].text.strip
41
+ version = version_text if version_text.match(VERSION_REGEX)
35
42
 
36
43
  dev_links = html.css(APP_DEV_URL_CSS_PATH)
37
- dev_url = String.new
44
+ dev_url = ""
38
45
  if !dev_links.empty? && dev_links.first.text.match(/Visit Developer's Website/)
39
- regex = /q=(https?:\/\/[\S]+?)&/
40
- dev_url = dev_links.first.attributes['href'].value.match(regex)[1]
46
+ dev_url = dev_links.first.attributes['href'].value.match(URL_REGEX)[1]
41
47
  end
42
48
 
43
49
  app_info.app_name = name.text
@@ -49,6 +55,7 @@ module PlayScrape
49
55
  app_info.dev_url = dev_url
50
56
  app_info.min_installs = installs.first
51
57
  app_info.max_installs = installs.last
58
+ app_info.version = version
52
59
 
53
60
  app_info
54
61
  end
@@ -5,15 +5,17 @@ class PlayScrapeTest < Test::Unit::TestCase
5
5
  TEST_PACKAGE = 'com.ea.game.fifa14_na'
6
6
  def test_scraping_app_information
7
7
  app_info = PlayScrape.scrape_app_info(TEST_PACKAGE)
8
+ puts app_info.version
8
9
 
9
10
 
10
11
  assert_equal 'FIFA 14 by EA SPORTS™', app_info.app_name
11
12
  assert_equal 'com.ea.game.fifa14_na', app_info.package_name, "Package name does not match"
12
13
  assert_equal 4.6, app_info.rating, "Play rating does not match"
13
- assert_equal 500000, app_info.min_installs
14
- assert_equal 1000000, app_info.max_installs
14
+ assert_equal 1000000, app_info.min_installs
15
+ assert_equal 5000000, app_info.max_installs
15
16
  assert_operator 36514, :<=, app_info.num_ratings
16
17
  assert_match 'REAL PLAYERS. REAL TEAMS. REAL LEAGUES.', app_info.description, "Description doesn't match"
17
18
  assert_match 'http://help.ea.com', app_info.dev_url, "Developer url doesn't match"
19
+ assert_equal '1.3.2', app_info.version
18
20
  end
19
21
  end