From dc6d037768b4e4dac1def1ad787be785fa5e062a Mon Sep 17 00:00:00 2001 From: danijoo Date: Wed, 1 Jan 2014 19:59:06 +0100 Subject: [PATCH] calls now accept codeblocks - lets call this version 1.0.0 --- lib/sightstone/modules/champion_module.rb | 6 ++++- lib/sightstone/modules/datadragon_module.rb | 6 ++++- lib/sightstone/modules/game_module.rb | 7 +++++- lib/sightstone/modules/league_module.rb | 6 ++++- lib/sightstone/modules/stats_module.rb | 14 +++++++++-- lib/sightstone/modules/summoner_module.rb | 27 ++++++++++++++++++--- lib/sightstone/modules/team_module.rb | 6 ++++- sightstone.gemspec | 2 +- 8 files changed, 62 insertions(+), 12 deletions(-) diff --git a/lib/sightstone/modules/champion_module.rb b/lib/sightstone/modules/champion_module.rb index bec4a62..15a037c 100644 --- a/lib/sightstone/modules/champion_module.rb +++ b/lib/sightstone/modules/champion_module.rb @@ -23,7 +23,11 @@ class ChampionModule < SightstoneBaseModule data['champions'].each do |champ| champions << Champion.new(champ) end - return champions + if block_given? + yield champions + else + return champions + end } end end \ No newline at end of file diff --git a/lib/sightstone/modules/datadragon_module.rb b/lib/sightstone/modules/datadragon_module.rb index 2232100..f4a8c77 100644 --- a/lib/sightstone/modules/datadragon_module.rb +++ b/lib/sightstone/modules/datadragon_module.rb @@ -13,7 +13,11 @@ class DatadragonModule < SightstoneBaseModule response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) - return data['v'] + if block_given? + yield data['v'] + else + return data['v'] + end } end diff --git a/lib/sightstone/modules/game_module.rb b/lib/sightstone/modules/game_module.rb index 974fda2..a42e309 100644 --- a/lib/sightstone/modules/game_module.rb +++ b/lib/sightstone/modules/game_module.rb @@ -25,7 +25,12 @@ class GameModule < SightstoneBaseModule response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) - return MatchHistory.new(data) + history = MatchHistory.new(data) + if block_given? + yield history + else + return history + end } end diff --git a/lib/sightstone/modules/league_module.rb b/lib/sightstone/modules/league_module.rb index f98dcba..1a3fdbb 100644 --- a/lib/sightstone/modules/league_module.rb +++ b/lib/sightstone/modules/league_module.rb @@ -29,7 +29,11 @@ class LeagueModule < SightstoneBaseModule leagueKeys.each do |key| leagues << League.new(data[key]) end - return leagues + if block_given? + yield leagues + else + return leagues + end } end diff --git a/lib/sightstone/modules/stats_module.rb b/lib/sightstone/modules/stats_module.rb index 37ad970..f603b13 100644 --- a/lib/sightstone/modules/stats_module.rb +++ b/lib/sightstone/modules/stats_module.rb @@ -31,7 +31,12 @@ class StatsModule < SightstoneBaseModule _parse_response(response) { |resp| data = JSON.parse(resp) - return PlayerStatsSummaryList.new(data) + statList = PlayerStatsSummaryList.new(data) + if block_given? + yield statList + else + return statList + end } end @@ -57,7 +62,12 @@ class StatsModule < SightstoneBaseModule _parse_response(response) { |resp| data = JSON.parse(resp) - return RankedStats.new(data) + stats = RankedStats.new(data) + if block_given? + yield stats + else + return stats + end } end diff --git a/lib/sightstone/modules/summoner_module.rb b/lib/sightstone/modules/summoner_module.rb index 4c122de..8165b1f 100644 --- a/lib/sightstone/modules/summoner_module.rb +++ b/lib/sightstone/modules/summoner_module.rb @@ -26,7 +26,12 @@ class SummonerModule < SightstoneBaseModule response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) - return Summoner.new(data) + s = Summoner.new(data) + if block_given? + yield s + else + return s + end } end @@ -46,7 +51,11 @@ class SummonerModule < SightstoneBaseModule names_array.each do |summoner| names_hash[summoner['id']] = summoner['name'] end - return names_hash + if block_given? + yield names_hash + else + return names_hash + end } end @@ -65,7 +74,12 @@ class SummonerModule < SightstoneBaseModule response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) - return RuneBook.new(data) + book = RuneBook.new(data) + if block_given? + yield book + else + return book + end } end @@ -84,7 +98,12 @@ class SummonerModule < SightstoneBaseModule response = _get_api_response(uri) _parse_response(response) { |resp| data = JSON.parse(resp) - return MasteryBook.new(data) + book = MasteryBook.new(data) + if block_given? + yield book + else + return book + end } end end diff --git a/lib/sightstone/modules/team_module.rb b/lib/sightstone/modules/team_module.rb index f3a8c53..22689bd 100644 --- a/lib/sightstone/modules/team_module.rb +++ b/lib/sightstone/modules/team_module.rb @@ -29,7 +29,11 @@ class TeamModule < SightstoneBaseModule data.each do |team| teams << Team.new(team) end - return teams + if block_given? + yield teams + else + return teams + end } end diff --git a/sightstone.gemspec b/sightstone.gemspec index 9f07d9e..f51de61 100644 --- a/sightstone.gemspec +++ b/sightstone.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'sightstone' - s.version = '0.9.1' + s.version = '1.0.0' s.date = '2014-01-01' s.summary = 'Ruby wrapper for riots league of legends api' s.description = s.summary