1
0
Fork 0
dokkan-data-rails/app/serializers/api/v1/card_serializer.rb

72 lines
1.5 KiB
Ruby
Raw Normal View History

class Api::V1::CardSerializer < Api::V1::BaseSerializer
2015-10-20 22:27:52 -04:00
attributes :character, :rarity, :type, :leader_skill, :passive_skill,
:super_attack, :awaken_type, :dokkan_card, :links, :title,
2015-10-20 22:27:52 -04:00
:gameid, :hp_stat, :atk_stat, :def_stat
private
def links
ActiveModel::ArraySerializer.new(
object.links,
each_serializer: Api::V1::LinkSerializer,
root: false
)
end
def character
2015-10-20 22:27:52 -04:00
object.character.attributes.slice('name').values.first
end
def rarity
2015-10-20 22:27:52 -04:00
object.rarity.attributes.slice('name').values.first
end
def type
2015-10-20 22:27:52 -04:00
object.type.attributes.slice('name').values.first
end
def leader_skill
2015-10-20 22:27:52 -04:00
if object.leader_skill
object.leader_skill.attributes.slice('description').values.first
end
end
def passive_skill
2015-10-20 22:27:52 -04:00
if object.passive_skill
object.passive_skill.attributes.slice('name', 'description')
end
end
def super_attack
2015-10-20 22:27:52 -04:00
if object.super_attack
object.super_attack.attributes.slice('name', 'description')
end
end
def awaken_type
2015-10-20 22:27:52 -04:00
object.awaken_type.attributes.slice('name').values.first
end
def dokkan_card
2015-10-20 22:27:52 -04:00
Api::V1::CardSerializer.new(object.dokkan_card, root: false)
end
def hp_stat
stat_formatter(object.hp_stat)
end
def atk_stat
stat_formatter(object.atk_stat)
end
def def_stat
stat_formatter(object.def_stat)
end
private
def stat_formatter(stat)
stat.attributes.slice('min', 'max', 'awaken_min', 'awaken_max')
end
end