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 +4 -4
- data/LICENSE +17 -0
- data/README.md +36 -0
- data/Rakefile +8 -0
- data/lib/gogcom.rb +5 -5
- data/lib/gogcom/game.rb +5 -0
- data/lib/gogcom/gogcom.rb +76 -0
- data/lib/gogcom/version.rb +5 -0
- data/test/test_gogcom.rb +58 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c72a8ba9c2b4c5449295cc91b4f1aca82594d4
|
4
|
+
data.tar.gz: 108ed27e57ba9627439ae2052c03a318a1ff555c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/gogcom.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
require 'gogcom/gogcom'
|
5
|
+
require 'gogcom/game'
|
data/lib/gogcom/game.rb
ADDED
@@ -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
|
data/test/test_gogcom.rb
ADDED
@@ -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.
|
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
|