2015-10-08 14:20:56 -04:00
|
|
|
class Api::V1::CardSerializer < Api::V1::BaseSerializer
|
2015-10-20 22:27:52 -04:00
|
|
|
attributes :character, :rarity, :type, :leader_skill, :passive_skill,
|
2015-10-08 14:20:56 -04:00
|
|
|
:super_attack, :awaken_type, :dokkan_card, :links, :title,
|
2015-10-20 22:27:52 -04:00
|
|
|
:gameid, :hp_stat, :atk_stat, :def_stat
|
2015-10-08 14:20:56 -04:00
|
|
|
|
|
|
|
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
|
2015-10-08 14:20:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def rarity
|
2015-10-20 22:27:52 -04:00
|
|
|
object.rarity.attributes.slice('name').values.first
|
2015-10-08 14:20:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
2015-10-20 22:27:52 -04:00
|
|
|
object.type.attributes.slice('name').values.first
|
2015-10-08 14:20:56 -04:00
|
|
|
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
|
2015-10-08 14:20:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def passive_skill
|
2015-10-20 22:27:52 -04:00
|
|
|
if object.passive_skill
|
|
|
|
object.passive_skill.attributes.slice('name', 'description')
|
|
|
|
end
|
2015-10-08 14:20:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def super_attack
|
2015-10-20 22:27:52 -04:00
|
|
|
if object.super_attack
|
|
|
|
object.super_attack.attributes.slice('name', 'description')
|
|
|
|
end
|
2015-10-08 14:20:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def awaken_type
|
2015-10-20 22:27:52 -04:00
|
|
|
object.awaken_type.attributes.slice('name').values.first
|
2015-10-08 14:20:56 -04:00
|
|
|
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')
|
2015-10-08 14:20:56 -04:00
|
|
|
end
|
|
|
|
end
|