class BN::Middleware::D3::Profile
Transforms a Hash into an Entity::Profile instance.
Public Instance Methods
execute(data)
click to toggle source
Execute the middleware.
@return [Entity::Profile]
# File lib/bn/middleware/d3/profile.rb, line 12 def execute(data) convert_heroes(data) convert_time_played(data) Entity::D3::Profile.new(data) end
Protected Instance Methods
convert_heroes(data)
click to toggle source
# File lib/bn/middleware/d3/profile.rb, line 21 def convert_heroes(data) data[:heroes].each do |hero| hero[:hero_class] = hero.delete(:class).tr("-", "_").downcase.to_sym hero[:gender] = hero[:gender] == 0 ? :male : :female end end
convert_time_played(data)
click to toggle source
# File lib/bn/middleware/d3/profile.rb, line 28 def convert_time_played(data) data[:time_played].keys.each do |hero_class| value = data[:time_played].delete(hero_class).to_f hero_class = hero_class.tr("-", "_").downcase.to_sym hero[hero_class] = value end end