Class: Gogcom::Game
- Inherits:
-
Object
- Object
- Gogcom::Game
- Defined in:
- lib/gogcom/game.rb
Instance Attribute Summary collapse
-
#avg_rating ⇒ Object
Returns the value of attribute avg_rating.
-
#avg_ratings_count ⇒ Object
Returns the value of attribute avg_ratings_count.
-
#developer ⇒ Object
Returns the value of attribute developer.
-
#download_size ⇒ Object
Returns the value of attribute download_size.
-
#game_modes ⇒ Object
Returns the value of attribute game_modes.
-
#genres ⇒ Object
Returns the value of attribute genres.
-
#languages ⇒ Object
Returns the value of attribute languages.
-
#platforms ⇒ Object
Returns the value of attribute platforms.
-
#price ⇒ Object
Returns the value of attribute price.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#release_date ⇒ Object
Returns the value of attribute release_date.
-
#reviews ⇒ Object
Returns the value of attribute reviews.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .get(game_name) ⇒ Object
- .get_avg_rating(data) ⇒ Object
- .get_avg_ratings_count(data) ⇒ Object
- .get_data(game_name) ⇒ Object
- .get_developer(data) ⇒ Object
- .get_download_size(data) ⇒ Object
- .get_genres(data) ⇒ Object
- .get_languages(data) ⇒ Object
- .get_modes(data) ⇒ Object
- .get_platforms(data) ⇒ Object
- .get_price(data) ⇒ Object
- .get_publisher(data) ⇒ Object
- .get_release_date(data) ⇒ Object
- .get_reviews(data) ⇒ Object
- .get_title(data) ⇒ Object
Instance Attribute Details
#avg_rating ⇒ Object
Returns the value of attribute avg_rating.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def @avg_rating end |
#avg_ratings_count ⇒ Object
Returns the value of attribute avg_ratings_count.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def @avg_ratings_count end |
#developer ⇒ Object
Returns the value of attribute developer.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def developer @developer end |
#download_size ⇒ Object
Returns the value of attribute download_size.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def download_size @download_size end |
#game_modes ⇒ Object
Returns the value of attribute game_modes.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def game_modes @game_modes end |
#genres ⇒ Object
Returns the value of attribute genres.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def genres @genres end |
#languages ⇒ Object
Returns the value of attribute languages.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def languages @languages end |
#platforms ⇒ Object
Returns the value of attribute platforms.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def platforms @platforms end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def price @price end |
#publisher ⇒ Object
Returns the value of attribute publisher.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def publisher @publisher end |
#release_date ⇒ Object
Returns the value of attribute release_date.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def release_date @release_date end |
#reviews ⇒ Object
Returns the value of attribute reviews.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def reviews @reviews end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/gogcom/game.rb', line 3 def title @title end |
Class Method Details
.get(game_name) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/gogcom/game.rb', line 99 def self.get(game_name) data = self.get_data(game_name) game = Game.new game.title = get_title(data) game.genres = get_genres(data) game.download_size = get_download_size(data) game.release_date = get_release_date(data) game.price = get_price(data) game. = (data) game. = (data) game.platforms = get_platforms(data) game.languages = get_languages(data) game.developer = get_developer(data) game.publisher = get_publisher(data) game.game_modes = get_modes(data) game.reviews = get_reviews(data) game end |
.get_avg_rating(data) ⇒ Object
40 41 42 |
# File 'lib/gogcom/game.rb', line 40 def self.(data) data["gameProductData"]["rating"].to_s.insert(1, ".") end |
.get_avg_ratings_count(data) ⇒ Object
44 45 46 |
# File 'lib/gogcom/game.rb', line 44 def self.(data) data["gameProductData"]["votesCount"] end |
.get_data(game_name) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/gogcom/game.rb', line 7 def self.get_data(game_name) name = Gogcom::Func.urlfy(game_name) page = Net::HTTP.get(URI("http://www.gog.com/game/" + name)) data = JSON.parse(page[/(?<=var gogData = )(.*)(?=;)/,1]) data end |
.get_developer(data) ⇒ Object
64 65 66 |
# File 'lib/gogcom/game.rb', line 64 def self.get_developer(data) data["gameProductData"]["developer"]["name"] end |
.get_download_size(data) ⇒ Object
28 29 30 |
# File 'lib/gogcom/game.rb', line 28 def self.get_download_size(data) data["gameProductData"]["downloadSize"] end |
.get_genres(data) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/gogcom/game.rb', line 18 def self.get_genres(data) genres = [] genres_raw = data["gameProductData"]["genres"] genres_raw.each do |genre| genres.push(genre["name"]) end genres end |
.get_languages(data) ⇒ Object
60 61 62 |
# File 'lib/gogcom/game.rb', line 60 def self.get_languages(data) data["gameProductData"]["languages"] end |
.get_modes(data) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/gogcom/game.rb', line 72 def self.get_modes(data) game_modes = [] modes_raw = data["gameProductData"]["modes"] modes_raw.each do |mode| game_modes.push(mode["title"]) end game_modes end |
.get_platforms(data) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gogcom/game.rb', line 48 def self.get_platforms(data) platforms = [] platforms_raw = data["gameProductData"]["worksOn"] platforms_raw.each do |platform| if(platform[1]) platforms.push(platform[0]) end end platforms end |
.get_price(data) ⇒ Object
36 37 38 |
# File 'lib/gogcom/game.rb', line 36 def self.get_price(data) data["gameProductData"]["price"]["symbol"] + data["gameProductData"]["price"]["amount"] end |
.get_publisher(data) ⇒ Object
68 69 70 |
# File 'lib/gogcom/game.rb', line 68 def self.get_publisher(data) data["gameProductData"]["publisher"]["name"] end |
.get_release_date(data) ⇒ Object
32 33 34 |
# File 'lib/gogcom/game.rb', line 32 def self.get_release_date(data) data["gameProductData"]["releaseDate"] end |
.get_reviews(data) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gogcom/game.rb', line 82 def self.get_reviews(data) reviews = [] reviews_raw = data["reviews"]["pages"][0] reviews_raw.each do |review| r = Review.new r.title = review["title"] r. = review["rating"].to_s.insert(1, ".") r. = review["author"]["name"] r.body = review["description"] reviews.push(r) end reviews end |
.get_title(data) ⇒ Object
14 15 16 |
# File 'lib/gogcom/game.rb', line 14 def self.get_title(data) data["gameProductData"]["title"] end |