gogcom 0.0.0 → 0.0.1

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: 0e1d6967ad6c7ecfc991f8edd4d63ceeba1066e8
4
- data.tar.gz: b816a053c8078a68f91d7d001d6bd2006dbe1245
3
+ metadata.gz: 74c72a8ba9c2b4c5449295cc91b4f1aca82594d4
4
+ data.tar.gz: 108ed27e57ba9627439ae2052c03a318a1ff555c
5
5
  SHA512:
6
- metadata.gz: a0612eb25841f8a3eb06153179392c460730c487ceedc5ab87fbb0ca71c1749625b0cdf81086fe253d50f098b32faa9bb2ac098a45522c9a8906e4bd5fbeddf0
7
- data.tar.gz: bfd84acde48fbe001710d0efe61de41c53abc2db091900ba5e5f866faa69d59c5a473d572ebeeeb775c392a1116a1cd3df8b07bf879f9bd4cbe0f8e67cf3d49c
6
+ metadata.gz: e574319ae1d012e90a843e3147b9f81297cfeaf5e67cbba2793fcafb1ee0b18c076e61fa74bb15d3f9130fd04a1aa76d22c5edf06ac6bb7a0cd33a2d9bcfa555
7
+ data.tar.gz: 561714d03bb66c57ca0fa23821810f375b019a8cf25be19e0787b9e7c0615e4e122c51dfbf04088fc86c54418e2a17c91977eb7a4baf792d6a5a9979dbd41e59
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Copyright (c) 2014 Rolandas Barysas
2
+
3
+ This software is provided 'as-is', without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+ 2. Altered source versions must be plainly marked as such, and must not be
16
+ misrepresented as being the original software.
17
+ 3. This notice may not be removed or altered from any source distribution.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ gogcom [![](https://api.travis-ci.org/rb-/gogcom.svg?branch=develop)](https://travis-ci.org/rb-/gogcom)
2
+ ============
3
+
4
+ Gogcom is a Ruby library for easy querying gog.com website.
5
+
6
+ This library is in early stages and not ready for general use.
7
+
8
+ ## Usage
9
+
10
+ ```
11
+ gem 'gogcom', '~> 0.0.1'
12
+ bundle install
13
+ ```
14
+
15
+ ```ruby
16
+ require 'gogcom'
17
+
18
+ game = Gogcom.game("Spelunky")
19
+
20
+ game.title # => "Spelunky"
21
+ game.genres # => ["action", "adventure", "platformer"]
22
+ game.download_size # => "143 MB"
23
+ game.release_date # => "August 8, 2013"
24
+ game.price # => "$14.99"
25
+ game.avg_rating # => 4.5
26
+ game.avg_ratings_count # => 257
27
+ game.platforms # => ["Windows (XP, Vista, 7, 8)"]
28
+ game.languages # => ["English", "French", "Italian", "German", "Spanish"]
29
+ game.developer # => "Mossmouth"
30
+ game.publisher # => "Mossmouth"
31
+ game.game_modes # => ["single-player", "multi-player", "co-op"]
32
+ ```
33
+
34
+ ## License
35
+
36
+ This code is free software; you can redistribute it and/or modify it under the terms of the zlib License. A copy of this license can be found in the included LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
data/lib/gogcom.rb CHANGED
@@ -1,5 +1,5 @@
1
- class Gogcom
2
- def self.hi
3
- puts "Hello World"
4
- end
5
- end
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ require 'gogcom/gogcom'
5
+ require 'gogcom/game'
@@ -0,0 +1,5 @@
1
+ class Game
2
+ attr_accessor :title, :genres, :download_size, :release_date, :price, :avg_rating,
3
+ :avg_ratings_count, :platforms, :languages, :developer, :publisher,
4
+ :game_modes
5
+ end
@@ -0,0 +1,76 @@
1
+ class Gogcom
2
+
3
+ GOG_GAME_BASE_URL = "http://www.gog.com/game/"
4
+
5
+ def self.game(name)
6
+ name = urlfy_name(name)
7
+ page = Nokogiri::HTML(open(GOG_GAME_BASE_URL + name))
8
+
9
+ game = Game.new
10
+
11
+ # Game title
12
+ title_raw = page.css('title').text
13
+ game.title = title_raw.slice(0..(title_raw.index('for download')-2))
14
+
15
+ # Game genres
16
+ game.genres = []
17
+ genres_raw = page.css('ul.game-specification li')[0].css('.data b')
18
+ genres_raw.each do |genre|
19
+ game.genres.push(genre.css('a').text)
20
+ end
21
+
22
+ # Download size
23
+ game.download_size = page.css('ul.game-specification li.download_size .data b')[0].text
24
+
25
+ # Release date
26
+ game.release_date = page.css('ul.game-specification li')[3].css('.data')[0].text
27
+
28
+ # Price
29
+ price = page.css('form #game_price').attr('value').text
30
+ game.price = "$" + (price.to_f / 100).to_s
31
+
32
+ # Average rating
33
+ game.avg_rating = 0.0
34
+ stuff_raw = page.css('ul.game-specification li')[2].css('.data .usr_rate span')
35
+ stuff_raw.each do |star|
36
+ if star.attr('class') == 'usr_s_f'
37
+ game.avg_rating += 1.0
38
+ elsif star.attr('class') == 'usr_s_h'
39
+ game.avg_rating += 0.5
40
+ end
41
+ end
42
+
43
+ # Rating count
44
+ avg_ratings_count_raw = page.css('ul.game-specification li')[2].css('.data span')[6].text
45
+ game.avg_ratings_count = avg_ratings_count_raw.gsub(/\D/, '').to_i
46
+
47
+ # Platforms
48
+ game.platforms = []
49
+ platforms_raw = page.css('ul.game-specification li')[4].css('.data')[0].text
50
+ game.platforms = platforms_raw.split(' and ')
51
+
52
+ # Languages
53
+ languages_raw = page.css('ul.game-specification li')[5].css('.data').text
54
+ game.languages = languages_raw.gsub("Audio and text:", "").gsub("Text only:", "")
55
+ .gsub(/\s+/, '').gsub('.', ',').split(',')
56
+
57
+ game.developer = page.css('ul.game-specification li')[6].css('.data a')[0].text # Developer
58
+ game.publisher = page.css('ul.game-specification li')[6].css('.data a')[0].text # Publisher
59
+
60
+ # Game modes
61
+ game.game_modes = []
62
+ game_modes_raw = page.css('ul.game-specification li')[7].css('.data')[0].text
63
+ game_modes_raw = game_modes_raw.gsub(/\s+/, '') # Remove whitespaces
64
+ game.game_modes = game_modes_raw.split(',')
65
+
66
+ game
67
+ end
68
+
69
+ # Converts Game: Name 2 to game_name_2
70
+ # @param: game name {string}
71
+ # @return: converted game name {string}
72
+ def self.urlfy_name(name)
73
+ name = name.gsub(/[^0-9A-Za-z\s]/, '').gsub(/\s/, '_').downcase
74
+ return name
75
+ end
76
+ end
@@ -0,0 +1,5 @@
1
+ module Gogcom
2
+
3
+ VERSION = "0.0.1"
4
+
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'minitest/autorun'
2
+ require 'gogcom'
3
+
4
+ class GogcomTest < MiniTest::Test
5
+ def setup
6
+ @game = Gogcom.game("Faster Than Light")
7
+ end
8
+
9
+ # Game
10
+ def test_that_game_has_title
11
+ assert_equal "FTL: Advanced Edition", @game.title
12
+ end
13
+
14
+ def test_that_game_has_genres
15
+ assert_equal ["strategy", "simulation", "sci-fi"], @game.genres
16
+ end
17
+
18
+ def test_that_game_has_download_size
19
+ assert_equal "205 MB", @game.download_size
20
+ end
21
+
22
+ def test_that_game_has_release_date
23
+ assert_equal "September 14, 2012", @game.release_date
24
+ end
25
+
26
+ def test_that_game_has_price
27
+ assert_match /^\$\d+(\.\d{2})?$/, @game.price
28
+ end
29
+
30
+ def test_that_game_has_avg_rating
31
+ assert_match /\d.\d/, @game.avg_rating.to_s
32
+ end
33
+
34
+ def test_that_game_has_avg_ratings_number
35
+ assert_kind_of Integer, @game.avg_ratings_count
36
+ end
37
+
38
+ def test_that_game_has_platforms
39
+ assert_equal ["Windows (XP, Vista, 7, 8)", "Mac OS X (10.6.8 or newer)"], @game.platforms
40
+ end
41
+
42
+ def test_that_game_has_languages
43
+ assert_equal ["English"], @game.languages
44
+ end
45
+
46
+ def test_that_game_has_developer
47
+ assert_equal "Subset Games", @game.developer
48
+ end
49
+
50
+ def test_that_game_has_publisher
51
+ assert_equal "Subset Games", @game.publisher
52
+ end
53
+
54
+ def test_that_game_has_game_modes
55
+ assert_equal ["single-player"], @game.game_modes
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gogcom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolandas Barysas
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-08-10 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.3.1
13
27
  description: Provides a simple, easy-to-use interface for gog.com website.
14
28
  email:
15
29
  - r.b@riseup.net
@@ -17,7 +31,14 @@ executables: []
17
31
  extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
20
37
  - lib/gogcom.rb
38
+ - lib/gogcom/game.rb
39
+ - lib/gogcom/gogcom.rb
40
+ - lib/gogcom/version.rb
41
+ - test/test_gogcom.rb
21
42
  homepage: http://rubygems.org/gems/gogcom
22
43
  licenses:
23
44
  - zlib