lib/smite/data_transform.rb in smite_ruby-1.4.5 vs lib/smite/data_transform.rb in smite_ruby-1.4.6

- old
+ new

@@ -22,25 +22,26 @@ ability_fields = data.slice(*ability_map_fields) return data if ability_fields.empty? data['abilities'] = ability_fields.values.map do |ability_data| data_attrs = ability_data.slice('Id', 'Summary', 'URL') - desc = ability_data['Description']['itemDescription'] + desc = ability_data['Description'] + desc = desc.nil? ? {} : desc['itemDescription'] Ability.new(data_attrs.merge(desc)) end data.except(*ability_filter_fields) end - def transform_recent_match(data) + def transform_match_summary(data) return data unless data['queue'] if data['queue'] =~ /League/ data else - data.except(*recent_match_filter_fields) + data.except(*match_summary_filter_fields) end end def transform_stats(data) stat_fields = data.slice(*stats_map_fields) @@ -65,12 +66,44 @@ value = value.tr('+', '').to_i data['amount'] = value data end + def transform_match_achievements(data) + ach_fields = data.slice(*match_achievement_map_fields) + return data if ach_fields.empty? + + data['match_achievements'] = MatchAchievements.new(ach_fields) + data.except(*match_achievement_filter_fields) + end + private + def match_achievement_map_fields + %w[ + kills_bot + kills_double + kills_fire_giant + kills_first_blood + kills_gold_fury + kills_penta + kills_phoenix + kills_player + kills_quadra + kills_siege_juggernaut + kills_single + kills_triple + kills_wild_juggernaut + player_name + match + ] + end + + def match_achievement_filter_fields + match_achievement_map_fields - %w(player_name match) + end + def item_map_fields %w( active_id1 active_id2 item_id1 item_id2 item_id3 item_id4 item_id5 item_id6 ) @@ -78,10 +111,13 @@ def item_filter_fields item_map_fields + %w( item_1 item_2 item_3 item_4 item_5 item_6 active_1 active_2 active_3 + item_active_1 item_active_2 item_active_3 + item_purch_1 item_purch_2 item_purch_3 + item_purch_4 item_purch_5 item_purch_6 ) end def ability_map_fields %w( ability_1 ability_2 ability_3 ability_4 ability_5 ) @@ -96,10 +132,10 @@ ability_description5 god_ability1_url god_ability2_url god_ability3_url god_ability4_url god_ability5_url ) end - def recent_match_filter_fields + def match_summary_filter_fields %w( ban1 ban2 ban3 ban4 ban5 ban6 ban1_id ban2_id ban3_id ban4_id ban5_id ban6_id ) \ No newline at end of file