pokeruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 34ea2228d544aadf83c38e48b487703f166f1e68
4
+ data.tar.gz: 06550a4decf619f2756285f59bc0f0d8e1888431
5
+ SHA512:
6
+ metadata.gz: fdefe715ac7fe49f933ba50689e1f89bfd501faaf0154c499ab7e3e168d1844e281f93183f2a22a8d9c7287ac741310c6f02f1cb58adadb5a8545a784a953966
7
+ data.tar.gz: 89ff8afe909f34e26376d99e635debe1f947d627194f07bf0cc867bc9ca25a29760bd32e07d65f14496dccf23d91a24bc5231422d94de17b1be72c7ce767a75a
@@ -0,0 +1,11 @@
1
+ # PokeApi
2
+ A ruby wrapper for http://pokeapi.co
3
+
4
+ ## Installation
5
+
6
+ gem install pokeruby
7
+
8
+ ## Usage
9
+
10
+ bulbasaur = Pokemon.new "bulbasaur"
11
+ bulbasaurMoves = bulbasaur.moves
@@ -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
@@ -0,0 +1,9 @@
1
+ require 'pokeruby/ability.rb'
2
+ require 'pokeruby/description.rb'
3
+ require 'pokeruby/egg_group.rb'
4
+ require 'pokeruby/game.rb'
5
+ require 'pokeruby/move.rb'
6
+ require 'pokeruby/pokedex.rb'
7
+ require 'pokeruby/pokemon.rb'
8
+ require 'pokeruby/sprite.rb'
9
+ require 'pokeruby/type.rb'
@@ -0,0 +1,17 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Ability < PokeApi
4
+
5
+ def initialize id
6
+ @ability = self.class.get "#{id}"
7
+ end
8
+
9
+ def name
10
+ @ability['name']
11
+ end
12
+
13
+ def description
14
+ @ability['description']
15
+ end
16
+
17
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Description < PokeApi
4
+
5
+ def initialize id
6
+ @description = self.class.get "#{id}"
7
+ end
8
+
9
+ def name
10
+ @description['name']
11
+ end
12
+
13
+ def description
14
+ @description['description']
15
+ end
16
+
17
+ def games
18
+ @description['games']
19
+ end
20
+
21
+ def pokemon
22
+ @description['pokemon']
23
+ end
24
+
25
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class EggGroup < PokeApi
4
+
5
+ def initialize id
6
+ @egg_group = self.class.get "#{id}"
7
+ end
8
+
9
+ def name
10
+ @egg_group['name']
11
+ end
12
+
13
+ def pokemon
14
+ @egg_group['pokemon']
15
+ end
16
+
17
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Game < PokeApi
4
+
5
+ def initialize id
6
+ @game = self.class.get "#{id}"
7
+ end
8
+
9
+ def name
10
+ @game['name']
11
+ end
12
+
13
+ def generation
14
+ @game['generation']
15
+ end
16
+
17
+ def release_year
18
+ @game['release_year']
19
+ end
20
+
21
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Move < PokeApi
4
+
5
+ def initialize id
6
+ @move = self.class.get "#{id}"
7
+ end
8
+
9
+ def name
10
+ @move['name']
11
+ end
12
+
13
+ def description
14
+ @move['description']
15
+ end
16
+
17
+ def power
18
+ @move['power']
19
+ end
20
+
21
+ def accuracy
22
+ @move['accuracy']
23
+ end
24
+
25
+ def category
26
+ @move['category']
27
+ end
28
+
29
+ def pp
30
+ @move['pp']
31
+ end
32
+
33
+ end
@@ -0,0 +1,18 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class PokeApi
5
+
6
+ def self.get url
7
+ JSON.parse Net::HTTP.get URI.parse "http://pokeapi.co#{url}".downcase
8
+ end
9
+
10
+ def self.get_resource url
11
+ self.get "/api/v1/#{url}"
12
+ end
13
+
14
+ def self.type_chart
15
+ @@type_chart ||= {}
16
+ end
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Pokedex < PokeApi
4
+ def self.national
5
+ @@national ||= get_resource 'pokedex/1/'
6
+ end
7
+ end
@@ -0,0 +1,117 @@
1
+ require_relative 'pokeapi'
2
+ require_relative 'type'
3
+ require_relative 'move'
4
+ require_relative 'ability'
5
+ require_relative 'description'
6
+
7
+ class Pokemon < PokeApi
8
+
9
+ def initialize id
10
+ @pokemon = self.class.get_resource "pokemon/#{id}/"
11
+ end
12
+
13
+ def national_id
14
+ @pokemon['national_id']
15
+ end
16
+
17
+ def name
18
+ @pokemon['name']
19
+ end
20
+
21
+ def types
22
+ @types ||= @pokemon['types'].collect { |type| Type.new type['resource_uri'] }
23
+ end
24
+
25
+ def abilities
26
+ @abilities ||= @pokemon['abilities'].collect { |ability| Ability.new ability['resource_uri'] }
27
+ end
28
+
29
+ def egg_groups
30
+ @egg_groups ||= @pokemon['egg_groups'].collect { |egg_group| EggGroup.new egg_group['resource_uri'] }
31
+ end
32
+
33
+ def evolutions
34
+ @evolutions ||= @pokemon['evolutions'].collect { |evolution| Pokemon.new evolution['resource_uri'] }
35
+ end
36
+
37
+ def descriptions
38
+ @descriptions ||= @pokemon['descriptions'].collect { |description| Description.new description['resource_uri'] }
39
+ end
40
+
41
+ def moves
42
+ @moves ||= @pokemon['moves'].collect { |move| Move.new move['resource_uri'] }
43
+ end
44
+
45
+ def catch_rate
46
+ @pokemon['catch_rate']
47
+ end
48
+
49
+ def species
50
+ @pokemon['species']
51
+ end
52
+
53
+ def hp
54
+ @pokemon['hp']
55
+ end
56
+
57
+ def attack
58
+ @pokemon['attack']
59
+ end
60
+
61
+ def defense
62
+ @pokemon['defense']
63
+ end
64
+
65
+ def sp_atk
66
+ @pokemon['sp_atk']
67
+ end
68
+
69
+ def sp_def
70
+ @pokemon['sp_def']
71
+ end
72
+
73
+ def speed
74
+ @pokemon['speed']
75
+ end
76
+
77
+ def total
78
+ @pokemon['total']
79
+ end
80
+
81
+ def egg_cycles
82
+ @pokemon['egg_cycles']
83
+ end
84
+
85
+ def ev_yield
86
+ @pokemon['ev_yield']
87
+ end
88
+
89
+ def exp
90
+ @pokemon['exp']
91
+ end
92
+
93
+ def growth_rate
94
+ @pokemon['growth_rate']
95
+ end
96
+
97
+ def height
98
+ @pokemon['height']
99
+ end
100
+
101
+ def weight
102
+ @pokemon['weight']
103
+ end
104
+
105
+ def happiness
106
+ @pokemon['happiness']
107
+ end
108
+
109
+ def male_female_ratio
110
+ @pokemon['male_female_ratio']
111
+ end
112
+
113
+ def equal? other
114
+ self.name == other.name
115
+ end
116
+
117
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Sprite < PokeApi
4
+
5
+ def initialize id
6
+ @sprite = self.class.get "#{id}"
7
+ end
8
+
9
+ def name
10
+ @sprite['name']
11
+ end
12
+
13
+ def pokemon
14
+ @sprite['pokemon']
15
+ end
16
+
17
+ def image
18
+ @sprite['image']
19
+ end
20
+
21
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'pokeapi'
2
+
3
+ class Type < PokeApi
4
+
5
+ def initialize id
6
+ @type = self.class.get "#{id}"
7
+ self.class.type_chart[self.name] ||= self
8
+ end
9
+
10
+ def name
11
+ @type['name']
12
+ end
13
+
14
+ def ineffective
15
+ @ineffective ||= @type['ineffective'].collect { |type| create_type ty }
16
+ end
17
+
18
+ def no_effect
19
+ @no_effect ||= @type['no_effect'].collect { |type| create_type type }
20
+ end
21
+
22
+ def resistance
23
+ @resistance ||= @type['resistance'].collect { |type| create_type type }
24
+ end
25
+
26
+ def super_effective
27
+ @super_effective ||= @type['super_effective'].collect { |type| create_type type }
28
+ end
29
+
30
+ def weakness
31
+ @weakness ||= @type['weakness'].collect { |type| create_type type }
32
+ end
33
+
34
+ def create_type type
35
+ self.class.type_chart[type['name'].capitalize] ||= Type.new type['resource_uri']
36
+ end
37
+
38
+ end
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'pokeruby'
3
+ s.version = '0.0.1'
4
+ s.date = '2014-03-18'
5
+ s.summary = "A wrapper for pokeapi.co"
6
+ s.description = "A wrapper for pokeapi.co"
7
+ s.authors = ["Hani Kazmi"]
8
+ s.email = 'hanikazmi@me.com'
9
+ s.files = `git ls-files`.split("\n") - %w(.rvmrc .gitignore)
10
+ s.homepage = 'https://github.com/HaniKazmi/PokeApi/branches'
11
+ s.license = 'MIT'
12
+ end
@@ -0,0 +1,16 @@
1
+ require "test/unit"
2
+ require 'pokeruby/ability'
3
+
4
+ class TestAbility < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert Ability.new '/api/v1/ability/1/'
8
+ end
9
+
10
+ def test_methods
11
+ ability = Ability.new '/api/v1/ability/1/'
12
+ assert_respond_to ability, :name
13
+ assert_respond_to ability, :description
14
+ end
15
+
16
+ end
@@ -0,0 +1,18 @@
1
+ require "test/unit"
2
+ require 'pokeruby/description'
3
+
4
+ class TestDescription < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert Description.new '/api/v1/description/2/'
8
+ end
9
+
10
+ def test_methods
11
+ description = Description.new '/api/v1/description/2/'
12
+ assert_respond_to description, :name
13
+ assert_respond_to description, :description
14
+ assert_respond_to description, :games
15
+ assert_respond_to description, :pokemon
16
+ end
17
+
18
+ end
@@ -0,0 +1,17 @@
1
+ require "test/unit"
2
+ require 'pokeruby/game'
3
+
4
+ class TestGame < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert Game.new '/api/v1/game/1/'
8
+ end
9
+
10
+ def test_methods
11
+ game = Game.new '/api/v1/game/1/'
12
+ assert_respond_to game, :name
13
+ assert_respond_to game, :generation
14
+ assert_respond_to game, :release_year
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ require "test/unit"
2
+ require 'pokeruby/move'
3
+
4
+ class TestMove < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert Move.new '/api/v1/move/1/'
8
+ end
9
+
10
+ def test_methods
11
+ move = Move.new '/api/v1/move/1/'
12
+ assert_respond_to move, :name
13
+ assert_respond_to move, :description
14
+ assert_respond_to move, :power
15
+ assert_respond_to move, :accuracy
16
+ assert_respond_to move, :category
17
+ assert_respond_to move, :pp
18
+ end
19
+
20
+ end
@@ -0,0 +1,9 @@
1
+ require "test/unit"
2
+ require 'pokeruby/pokedex'
3
+
4
+ class TestPokedex < Test::Unit::TestCase
5
+ def test_constuctor
6
+ assert Pokedex.national
7
+ end
8
+
9
+ end
@@ -0,0 +1,38 @@
1
+ require "test/unit"
2
+ require 'pokeruby/pokemon'
3
+
4
+ class TestPokemon < Test::Unit::TestCase
5
+ def test_constuctor
6
+ assert Pokemon.new 1
7
+ end
8
+
9
+ def test_methods
10
+ pokemon = Pokemon.new 1
11
+ assert_respond_to pokemon, :national_id
12
+ assert_respond_to pokemon, :name
13
+ assert_respond_to pokemon, :types
14
+ assert_respond_to pokemon, :abilities
15
+ assert_respond_to pokemon, :egg_groups
16
+ assert_respond_to pokemon, :evolutions
17
+ assert_respond_to pokemon, :descriptions
18
+ assert_respond_to pokemon, :moves
19
+ assert_respond_to pokemon, :catch_rate
20
+ assert_respond_to pokemon, :species
21
+ assert_respond_to pokemon, :egg_cycles
22
+ assert_respond_to pokemon, :ev_yield
23
+ assert_respond_to pokemon, :exp
24
+ assert_respond_to pokemon, :growth_rate
25
+ assert_respond_to pokemon, :height
26
+ assert_respond_to pokemon, :weight
27
+ assert_respond_to pokemon, :happiness
28
+ assert_respond_to pokemon, :male_female_ratio
29
+ end
30
+
31
+ def test_bulbasaur
32
+ bulbasaur = Pokemon.new "bulbasaur"
33
+ assert bulbasaur
34
+ bulbasaur_cap = Pokemon.new "Bulbasaur"
35
+ assert bulbasaur_cap
36
+ assert_same bulbasaur, bulbasaur_cap
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ require "test/unit"
2
+ require 'pokeruby/sprite'
3
+
4
+ class TestSprite < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert Sprite.new '/api/v1/sprite/1/'
8
+ end
9
+
10
+ def test_methods
11
+ sprite = Sprite.new '/api/v1/sprite/1/'
12
+ assert_respond_to sprite, :name
13
+ assert_respond_to sprite, :pokemon
14
+ assert_respond_to sprite, :image
15
+ end
16
+
17
+ end
@@ -0,0 +1,30 @@
1
+ require "test/unit"
2
+ require 'pokeruby/type'
3
+
4
+ class TestType < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert Type.new '/api/v1/type/1/'
8
+ end
9
+
10
+ def test_methods
11
+ type = Type.new '/api/v1/type/1/'
12
+ assert_respond_to type, :name
13
+ assert_respond_to type, :ineffective
14
+ assert_respond_to type, :no_effect
15
+ assert_respond_to type, :resistance
16
+ assert_respond_to type, :super_effective
17
+ assert_respond_to type, :weakness
18
+ assert_respond_to type, :create_type
19
+ end
20
+
21
+ def test_type_chart
22
+ (1..18).each do |i|
23
+ type = Type.new "/api/v1/type/#{i}/"
24
+ chart_size = Type.type_chart.size
25
+ assert type.weakness
26
+ type.weakness.each { |j| assert_not_nil Type.type_chart[j.name] }
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,16 @@
1
+ require "test/unit"
2
+ require 'pokeruby/egg_group'
3
+
4
+ class TestEggGroup < Test::Unit::TestCase
5
+
6
+ def test_constructor
7
+ assert EggGroup.new '/api/v1/egg/1/'
8
+ end
9
+
10
+ def test_methods
11
+ egg_group = EggGroup.new '/api/v1/egg/1/'
12
+ assert_respond_to egg_group, :name
13
+ assert_respond_to egg_group, :pokemon
14
+ end
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pokeruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hani Kazmi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A wrapper for pokeapi.co
14
+ email: hanikazmi@me.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - Rakefile
21
+ - lib/pokeruby.rb
22
+ - lib/pokeruby/ability.rb
23
+ - lib/pokeruby/description.rb
24
+ - lib/pokeruby/egg_group.rb
25
+ - lib/pokeruby/game.rb
26
+ - lib/pokeruby/move.rb
27
+ - lib/pokeruby/pokeapi.rb
28
+ - lib/pokeruby/pokedex.rb
29
+ - lib/pokeruby/pokemon.rb
30
+ - lib/pokeruby/sprite.rb
31
+ - lib/pokeruby/type.rb
32
+ - pokeruby.gemspec
33
+ - test/test_Ability.rb
34
+ - test/test_Description.rb
35
+ - test/test_Game.rb
36
+ - test/test_Move.rb
37
+ - test/test_Pokedex.rb
38
+ - test/test_Pokemon.rb
39
+ - test/test_Sprite.rb
40
+ - test/test_Type.rb
41
+ - test/test_egg_group.rb
42
+ homepage: https://github.com/HaniKazmi/PokeApi/branches
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.1.11
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: A wrapper for pokeapi.co
66
+ test_files: []