playlyfe_client 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/Gemfile +9 -0
  4. data/Gemfile.lock +50 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +97 -0
  7. data/Rakefile +10 -0
  8. data/lib/playlyfe_client/action.rb +32 -0
  9. data/lib/playlyfe_client/connection.rb +200 -0
  10. data/lib/playlyfe_client/errors.rb +42 -0
  11. data/lib/playlyfe_client/game.rb +33 -0
  12. data/lib/playlyfe_client/leaderboard.rb +27 -0
  13. data/lib/playlyfe_client/metric.rb +14 -0
  14. data/lib/playlyfe_client/player.rb +80 -0
  15. data/lib/playlyfe_client/team.rb +26 -0
  16. data/lib/playlyfe_client/v2/action.rb +59 -0
  17. data/lib/playlyfe_client/v2/collection/action_collection.rb +30 -0
  18. data/lib/playlyfe_client/v2/collection/leaderboard_collection.rb +43 -0
  19. data/lib/playlyfe_client/v2/collection/metric_collection.rb +30 -0
  20. data/lib/playlyfe_client/v2/collection/player_collection.rb +30 -0
  21. data/lib/playlyfe_client/v2/collection/team_collection.rb +31 -0
  22. data/lib/playlyfe_client/v2/collection.rb +60 -0
  23. data/lib/playlyfe_client/v2/connection.rb +109 -0
  24. data/lib/playlyfe_client/v2/game.rb +71 -0
  25. data/lib/playlyfe_client/v2/leaderboard/players_leaderboard.rb +30 -0
  26. data/lib/playlyfe_client/v2/leaderboard/teams_leaderboard.rb +30 -0
  27. data/lib/playlyfe_client/v2/leaderboard/unknown_leaderboard.rb +23 -0
  28. data/lib/playlyfe_client/v2/leaderboard.rb +38 -0
  29. data/lib/playlyfe_client/v2/metric/compound_metric.rb +31 -0
  30. data/lib/playlyfe_client/v2/metric/point_metric.rb +27 -0
  31. data/lib/playlyfe_client/v2/metric/set_metric.rb +41 -0
  32. data/lib/playlyfe_client/v2/metric/state_metric.rb +26 -0
  33. data/lib/playlyfe_client/v2/metric.rb +47 -0
  34. data/lib/playlyfe_client/v2/player.rb +135 -0
  35. data/lib/playlyfe_client/v2/team.rb +58 -0
  36. data/lib/playlyfe_client/version.rb +3 -0
  37. data/lib/playlyfe_client.rb +11 -0
  38. data/lib/string_addons.rb +9 -0
  39. data/playlyfe_client.gemspec +30 -0
  40. metadata +194 -0
@@ -0,0 +1,59 @@
1
+ require_relative "../action.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class Action < PlaylyfeClient::Action
6
+ attr_reader :id, :name, :description, :rewards, :variables, :times_played
7
+
8
+ private
9
+
10
+ def initialize(action_hash, game)
11
+ super(game)
12
+
13
+ @id=action_hash[:id] || action_hash["id"]
14
+ @name=action_hash[:name] || action_hash["name"]
15
+ @description=action_hash[:description] || action_hash["description"]
16
+ @variables=action_hash[:variables] || action_hash["variables"]
17
+ @times_played=action_hash[:count] || action_hash["count"] || action_hash[:times_played] || action_hash["times_played"]
18
+
19
+ fill_rewards(action_hash[:rewards] || action_hash["rewards"] || [])
20
+ end
21
+
22
+ def fill_rewards(rewards)
23
+ @rewards = []
24
+ rewards.each do |rwd_hash|
25
+ verb= rwd_hash[:verb] || rwd_hash["verb"]
26
+ probability= rwd_hash[:probability] || rwd_hash["probability"]
27
+
28
+ mtr=rwd_hash[:metric] || rwd_hash["metric"]
29
+ metric=game.metrics.find(mtr[:id] || mtr["id"])
30
+
31
+ value=rwd_hash[:value] || rwd_hash["value"]
32
+ if metric.kind_of?(PlaylyfeClient::V2::SetMetric)
33
+ value=get_rewards_array(value,metric)
34
+ id="#{metric.id}_#{(value.collect {|i| i[:name]}).join("_").underscore}"
35
+ else
36
+ value=value.to_i
37
+ id="#{metric.id}_#{value}"
38
+ end
39
+
40
+ @rewards << {id: id, metric: metric, value: value, verb: verb, probability: probability }
41
+ end
42
+
43
+ @rewards
44
+ end
45
+
46
+ def get_rewards_array(items_hash,metric)
47
+ items=[]
48
+ items_hash.each_pair do |key, val|
49
+ m_item= (metric.items.detect {|it| it[:name] == key})
50
+ items << {name: m_item[:name], count: val.to_i} unless m_item.nil?
51
+ end
52
+ items
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
59
+
@@ -0,0 +1,30 @@
1
+ require_relative "../collection.rb"
2
+ require_relative "../action.rb"
3
+
4
+ module PlaylyfeClient
5
+ module V2
6
+ class ActionCollection < PlaylyfeClient::V2::Collection
7
+
8
+ def find(str)
9
+ (@items.detect {|pl| pl.name == str || pl.id == str})
10
+ end
11
+
12
+ private
13
+
14
+ def initialize(game)
15
+ super
16
+ @items=[]
17
+ fill_items(game.connection.get_full_all_actions_array)
18
+ end
19
+
20
+ def fill_items(hash_array)
21
+ hash_array.each do |action_hash|
22
+ @items << PlaylyfeClient::V2::Action.new(action_hash, @game)
23
+ end
24
+ end
25
+
26
+
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,43 @@
1
+ require_relative "../collection.rb"
2
+ require_relative "../leaderboard/unknown_leaderboard.rb"
3
+ require_relative "../leaderboard/teams_leaderboard.rb"
4
+ require_relative "../leaderboard/players_leaderboard.rb"
5
+
6
+ module PlaylyfeClient
7
+ module V2
8
+ class LeaderboardCollection < PlaylyfeClient::V2::Collection
9
+
10
+ def find(str)
11
+ (@items.detect {|pl| pl.name == str || pl.id == str})
12
+ end
13
+
14
+ def for_teams
15
+ @items.select {|lbd| lbd.kind_of?(PlaylyfeClient::V2::TeamsLeaderboard)}
16
+ end
17
+
18
+ def for_players
19
+ @items.select {|lbd| lbd.kind_of?(PlaylyfeClient::V2::PlayersLeaderboard)}
20
+ end
21
+
22
+
23
+ private
24
+
25
+ def initialize(game)
26
+ super
27
+ @items=[]
28
+ fill_items(game.connection.get_full_leaderboards_array)
29
+ end
30
+
31
+ def fill_items(hash_array)
32
+ hash_array.each do |definition_hash|
33
+ data_hash=game.connection.get_full_leaderboard_hash(definition_hash["id"])
34
+ @items << PlaylyfeClient::V2::UnknownLeaderboard.create_from(definition_hash.merge(data_hash), @game)
35
+ end
36
+ end
37
+
38
+
39
+ end
40
+ end
41
+ end
42
+
43
+
@@ -0,0 +1,30 @@
1
+ require_relative "../collection.rb"
2
+ require_relative "../metric.rb"
3
+
4
+ module PlaylyfeClient
5
+ module V2
6
+ class MetricCollection < PlaylyfeClient::V2::Collection
7
+
8
+ def find(str)
9
+ (@items.detect {|pl| pl.name == str || pl.id == str})
10
+ end
11
+
12
+ private
13
+
14
+ def initialize(game)
15
+ super
16
+ @items=[]
17
+ fill_items(game.connection.get_full_metrics_array)
18
+ end
19
+
20
+ def fill_items(hash_array)
21
+ hash_array.each do |action_hash|
22
+ @items << PlaylyfeClient::V2::Metric.create_from(action_hash, @game)
23
+ end
24
+ end
25
+
26
+
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ require_relative "../collection.rb"
2
+ require_relative "../player.rb"
3
+
4
+ module PlaylyfeClient
5
+ module V2
6
+ class PlayerCollection < PlaylyfeClient::V2::Collection
7
+ def find(str)
8
+ (@items.detect {|pl| pl.alias.include?(str) || pl.id.include?(str)})
9
+ end
10
+
11
+ private
12
+
13
+ def initialize(game)
14
+ super
15
+ @items=[]
16
+ fill_items(@game.connection.get_player_hash_array)
17
+ end
18
+
19
+ def fill_items(player_hash_array)
20
+ player_hash_array.each do |player_hash|
21
+ @items << PlaylyfeClient::V2::Player.new(player_hash, @game)
22
+ end
23
+ end
24
+
25
+
26
+ end
27
+ end
28
+ end
29
+
30
+
@@ -0,0 +1,31 @@
1
+ require_relative "../collection.rb"
2
+ require_relative "../team.rb"
3
+
4
+ module PlaylyfeClient
5
+ module V2
6
+ class TeamCollection < PlaylyfeClient::V2::Collection
7
+
8
+ def find(str)
9
+ (@items.detect {|pl| pl.name == str || pl.id == str})
10
+ end
11
+
12
+ private
13
+
14
+ def initialize(game)
15
+ super
16
+ @items=[]
17
+ fill_items(@game.connection.get_team_hash_array)
18
+ end
19
+
20
+ def fill_items(hash_array)
21
+ hash_array.each do |item_hash|
22
+ @items << PlaylyfeClient::V2::Team.new(item_hash, @game)
23
+ end
24
+ end
25
+
26
+
27
+ end
28
+ end
29
+ end
30
+
31
+
@@ -0,0 +1,60 @@
1
+ module PlaylyfeClient
2
+ module V2
3
+ class Collection
4
+ attr_reader :game
5
+
6
+ def all
7
+ @items
8
+ end
9
+
10
+ def add(item)
11
+ @items << item
12
+ end
13
+
14
+ def find(str)
15
+ (@items.detect {|item| item.id.include?(str)})
16
+ end
17
+
18
+ def find_all(str_arr)
19
+ coll=[]
20
+ str_arr.each do |str|
21
+ coll << self.find(str)
22
+ end
23
+ coll.compact
24
+ end
25
+
26
+ def first
27
+ @items.first
28
+ end
29
+
30
+ def last
31
+ @items.last
32
+ end
33
+
34
+ def to_a
35
+ @items
36
+ end
37
+
38
+ def size
39
+ @items.size
40
+ end
41
+
42
+ private
43
+
44
+ #shoudl be redefined in subclasses
45
+ def initialize(game)
46
+ @game= game
47
+ @items=[]
48
+ fill_items([])
49
+ end
50
+
51
+ def fill_items(hash_array)
52
+ hash_array.each do |hash|
53
+ @items << hash
54
+ end
55
+ end
56
+
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,109 @@
1
+
2
+ require_relative "../connection.rb"
3
+
4
+ module PlaylyfeClient
5
+ module V2
6
+ class Connection < PlaylyfeClient::Connection
7
+
8
+ def game
9
+ @game ||= PlaylyfeClient::V2::Game.find_by_connection(self)
10
+ end
11
+
12
+ def reset_game!
13
+ @game=nil
14
+ end
15
+
16
+ #for calls to "runtime" there MUST be a player_id, even for Metrics or Leaderboards. So we pick first one.
17
+ def dummy_player_id
18
+ @dummy_player_id||= get_full_players_hash["data"].first["id"]
19
+ end
20
+
21
+ def dummy_player_id=(id)
22
+ @dummy_player_id= id
23
+ end
24
+
25
+ def get_full_game_hash
26
+ self.get('/admin')
27
+ end
28
+
29
+ def get_game_hash
30
+ get_full_game_hash["game"]
31
+ end
32
+
33
+ def get_full_players_hash
34
+ get("/admin/players")
35
+ end
36
+
37
+ def get_player_hash_array
38
+ get_full_players_hash["data"]
39
+ end
40
+
41
+ def get_game_image_data(player_id=dummy_player_id)
42
+ get_raw("/runtime/assets/game", {size: style.to_s, player_id: player_id})
43
+ end
44
+
45
+ def get_full_teams_hash
46
+ get("/admin/teams")
47
+ end
48
+
49
+ def get_team_hash_array
50
+ get_full_teams_hash["data"]
51
+ end
52
+
53
+ def get_full_player_profile_hash(player_id)
54
+ get("/admin/players/#{player_id}")
55
+ end
56
+
57
+ def get_full_team_members_hash(team_id)
58
+ get("/admin/teams/#{team_id}/members")
59
+ end
60
+
61
+ def get_team_members_hash_array(team_id)
62
+ get_full_team_members_hash(team_id)["data"]
63
+ end
64
+
65
+ def get_full_leaderboards_array(player_id=dummy_player_id)
66
+ get("/runtime/leaderboards", {player_id: player_id})
67
+ end
68
+
69
+ def get_full_leaderboard_hash(leaderboard_id, cycle="alltime", player_id=dummy_player_id)
70
+ get("/runtime/leaderboards/#{leaderboard_id}", {cycle: cycle, player_id: player_id})
71
+ end
72
+
73
+ def get_full_all_actions_array(player_id=dummy_player_id)
74
+ get("/runtime/actions", {player_id: player_id})
75
+ end
76
+
77
+ def post_play_action(action_id, player_id, body ={})
78
+ post("/runtime/actions/#{action_id}/play", {player_id: player_id}, body)
79
+ end
80
+
81
+ def get_full_metrics_array(player_id=dummy_player_id)
82
+ get("/runtime/definitions/metrics", {player_id: player_id})
83
+ end
84
+
85
+ def get_full_activity_feed_array(player_id, start_time=nil, end_time=nil)
86
+ start_str=start_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if start_time.kind_of?(Time)
87
+ end_str=end_time.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") if start_time.kind_of?(Time)
88
+
89
+ #/admin/players/player2/activity?start=2016-05-01T00:00:00Z&end=2016-05-21T00:00:00Z
90
+ if start_time
91
+ #get specified period of time
92
+ get("/admin/players/#{player_id}/activity",{"start" => start_str, "end" => end_str})
93
+ else
94
+ #get last 24 hours
95
+ get("/admin/players/#{player_id}/activity")
96
+ end
97
+ end
98
+
99
+ def post_create_player(player_h)
100
+ post("/admin/players", {}, player_h)
101
+ end
102
+
103
+ def delete_player(player_id)
104
+ delete("/admin/players/#{player_id}")
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,71 @@
1
+
2
+ require_relative "./collection/player_collection.rb"
3
+ require_relative "./collection/team_collection.rb"
4
+ require_relative "./collection/leaderboard_collection.rb"
5
+ require_relative "./collection/action_collection.rb"
6
+ require_relative "./collection/metric_collection.rb"
7
+
8
+ require_relative "../game.rb"
9
+
10
+ module PlaylyfeClient
11
+ module V2
12
+ #Game is 1:1 to connection, so only one instance per connection
13
+ #finding is done by credentials
14
+ class Game < PlaylyfeClient::Game
15
+
16
+ attr_reader :game_hash, :description, :id, :type, :timezone, :created_at
17
+ attr_accessor :ignore_rate_limit_errors
18
+
19
+ def self.find_by_connection(conn)
20
+ PlaylyfeClient::V2::Game.new(conn)
21
+ end
22
+
23
+ def players
24
+ @players ||= PlaylyfeClient::V2::PlayerCollection.new(self)
25
+ end
26
+
27
+ def teams
28
+ @teams ||= PlaylyfeClient::V2::TeamCollection.new(self)
29
+ end
30
+
31
+ def metrics
32
+ @metrics ||= PlaylyfeClient::V2::MetricCollection.new(self)
33
+ end
34
+
35
+ def actions
36
+ @actions ||= PlaylyfeClient::V2::ActionCollection.new(self)
37
+ end
38
+
39
+ def available_actions
40
+ actions
41
+ end
42
+
43
+ def leaderboards
44
+ @leaderboards ||= PlaylyfeClient::V2::LeaderboardCollection.new(self)
45
+ end
46
+
47
+ def image_data(style=:original)
48
+ data=connection.get_game_image_data
49
+ puts(data)
50
+ end
51
+
52
+ private
53
+
54
+ def initialize(conn)
55
+ super(conn)
56
+ @game_hash=connection.get_game_hash
57
+ #name is not name of Game but rather connection @name= game_hash["name"]
58
+ @description=game_hash["description"]
59
+ @id=game_hash["id"]
60
+ @image=game_hash["image"]
61
+ @title=game_hash["title"]
62
+ @type=game_hash["type"]
63
+ @timezone=game_hash["timezone"] #TODO converion to TZInfo::Timezone ? http://www.rubydoc.info/gems/tzinfo/frames
64
+ @created_at=Time.parse(game_hash["created"])
65
+ end
66
+
67
+
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "../leaderboard.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class PlayersLeaderboard < PlaylyfeClient::V2::Leaderboard
6
+
7
+ private
8
+
9
+ def fill_positions(data)
10
+ data.each do |pos|
11
+ rank=(pos[:rank] || pos["rank"]).to_i - 1
12
+ score=pos[:score] || pos["score"] || 0
13
+ entity= pos[:player] || pos["player"]
14
+
15
+ player=game.players.find(entity[:id] || entity["id"])
16
+
17
+ #all players should be listed in game, so if nothing is found raise exception
18
+ if player.nil?
19
+ fail PlaylyfeClient::LeaderboardError.new("{\"error\": \"Player not found\", \"error_description\": \"Player '#{entity[:id] || entity["id"]}' from '#{self.name}'[#{self.id}] leaderboard was not found between game.players!\"}")
20
+ end
21
+
22
+ @positions[rank] = {entity: player, score: score}
23
+ end
24
+
25
+ @positions
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "../leaderboard.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class TeamsLeaderboard < PlaylyfeClient::V2::Leaderboard
6
+
7
+ private
8
+
9
+ def fill_positions(data)
10
+ data.each do |pos|
11
+ rank=(pos[:rank] || pos["rank"]).to_i - 1
12
+ score=pos[:score] || pos["score"] || 0
13
+ entity= pos[:team] || pos["team"]
14
+
15
+ team=game.teams.find(entity[:id] || entity["id"])
16
+
17
+ #all teams should be listed in game, so if nothing is found raise exception
18
+ if team.nil?
19
+ fail PlaylyfeClient::LeaderboardError.new("{\"error\": \"Team not found\", \"error_description\": \"Team '#{entity[:id] || entity["id"]}' from '#{self.name}'[#{self.id}] leaderboard was not found between game.teams!\"}")
20
+ end
21
+
22
+ @positions[rank] = {entity: team, score: score}
23
+ end
24
+
25
+ @positions
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require_relative "../leaderboard.rb"
2
+ require_relative "./players_leaderboard.rb"
3
+ require_relative "./teams_leaderboard.rb"
4
+
5
+ module PlaylyfeClient
6
+ module V2
7
+ class UnknownLeaderboard < PlaylyfeClient::V2::Leaderboard
8
+
9
+ def self.create_from(lbd_hash, game)
10
+ entity=lbd_hash[:entity_type] || lbd_hash["entity_type"]
11
+ case entity
12
+ when "players"
13
+ return PlaylyfeClient::V2::PlayersLeaderboard.new(lbd_hash, game)
14
+ when "teams"
15
+ return PlaylyfeClient::V2::TeamsLeaderboard.new(lbd_hash, game)
16
+ else
17
+ fail PlaylyfeClient::LeaderboardError.new("{\"error\": \"Unrecognized entity_type\", \"error_description\": \"Class for entity_type '#{entity}' from #{lbd_hash} is unrecognized!\"}")
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "../leaderboard.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class Leaderboard < PlaylyfeClient::Leaderboard
6
+
7
+ attr_reader :entity_type, :metric, :scope, :cycles
8
+
9
+ private
10
+
11
+ def initialize(lbd_hash, game)
12
+ super(game)
13
+
14
+ @id=lbd_hash[:id] || lbd_hash["id"]
15
+ @name=lbd_hash[:name] || lbd_hash["name"]
16
+ @entity_type=lbd_hash[:entity_type] || lbd_hash["entity_type"]
17
+ @metric=lbd_hash[:metric] || lbd_hash["metric"]
18
+ @scope=lbd_hash[:scope] || lbd_hash["scope"]
19
+ @cycles=lbd_hash[:cycles] || lbd_hash["cycles"]
20
+
21
+ fill_positions(lbd_hash[:data] || lbd_hash["data"] || [])
22
+ end
23
+
24
+ def fill_positions(data)
25
+ data.each do |pos|
26
+ rank=(pos[:rank] || pos["rank"]).to_i - 1
27
+ score=pos[:score] || pos["score"] || 0
28
+ entity= pos[:player] || pos["player"] || pos[:team] || pos["team"] || nil
29
+
30
+ @positions[rank] = {entity: entity, score: score}
31
+ end
32
+
33
+ @positions
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../metric.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class CompoundMetric < PlaylyfeClient::V2::Metric
6
+ attr_reader :formula
7
+
8
+
9
+ def apply_reward(reward, scores)
10
+ metric_sym=self.id.to_sym
11
+ case reward[:verb]
12
+ when "add"
13
+ scores[:compounds][metric_sym]+=reward[:value].to_i
14
+ when "remove"
15
+ scores[:compounds][metric_sym]-=reward[:value].to_i
16
+ when "set"
17
+ scores[:compounds][metric_sym]=reward[:value].to_i
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def initialize(metric_hash, game)
24
+ super(metric_hash, game)
25
+
26
+ @formula=metric_hash[:formula] || metric_hash["formula"]
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ require_relative "../metric.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class PointMetric < PlaylyfeClient::V2::Metric
6
+
7
+ def apply_reward(reward, scores)
8
+ metric_sym=self.id.to_sym
9
+ case reward[:verb]
10
+ when "add"
11
+ scores[:points][metric_sym]+=reward[:value].to_i
12
+ when "remove"
13
+ scores[:points][metric_sym]-=reward[:value].to_i
14
+ when "set"
15
+ scores[:points][metric_sym]=reward[:value].to_i
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def initialize(metric_hash, game)
22
+ super(metric_hash, game)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ require_relative "../metric.rb"
2
+
3
+ module PlaylyfeClient
4
+ module V2
5
+ class SetMetric < PlaylyfeClient::V2::Metric
6
+ attr_reader :items
7
+
8
+ def apply_reward(reward, scores)
9
+ reward[:value].each do |rwd_item|
10
+ score_item=scores[:sets][self.id.to_sym].detect { |i| i[:name] == rwd_item[:name] }
11
+ case reward[:verb]
12
+ when "add"
13
+ score_item[:count]+=rwd_item[:count].to_i
14
+ when "remove"
15
+ score_item[:count]-=rwd_item[:count].to_i
16
+ when "set"
17
+ score_item[:count]=rwd_item[:count].to_i
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+
24
+ private
25
+
26
+ def initialize(metric_hash, game)
27
+ super(metric_hash, game)
28
+
29
+ fill_items(metric_hash["items"] || [])
30
+ end
31
+
32
+ def fill_items(items_hash)
33
+ @items=[]
34
+ items_hash.each_pair do |key, value|
35
+ @items << {name: key , description: value["description"]}
36
+ end
37
+ @items
38
+ end
39
+ end
40
+ end
41
+ end