1
0
Fork 0

Clean up api serializers

This commit is contained in:
Andrew Tomaka 2015-10-20 22:27:52 -04:00
parent 5232273a37
commit acf2ac26bb
2 changed files with 35 additions and 11 deletions

View file

@ -1,7 +1,7 @@
class Api::V1::CardSerializer < Api::V1::BaseSerializer
attributes :id, :character, :rarity, :type, :leader_skill, :passive_skill,
attributes :character, :rarity, :type, :leader_skill, :passive_skill,
:super_attack, :awaken_type, :dokkan_card, :links, :title,
:gameid
:gameid, :hp_stat, :atk_stat, :def_stat
private
@ -14,34 +14,58 @@ class Api::V1::CardSerializer < Api::V1::BaseSerializer
end
def character
Api::V1::CharacterSerializer.new(object.character)
object.character.attributes.slice('name').values.first
end
def rarity
Api::V1::RaritySerializer.new(object.rarity)
object.rarity.attributes.slice('name').values.first
end
def type
Api::V1::TypeSerializer.new(object.type)
object.type.attributes.slice('name').values.first
end
def leader_skill
Api::V1::LeaderSkillSerializer.new(object.leader_skill)
if object.leader_skill
object.leader_skill.attributes.slice('description').values.first
end
end
def passive_skill
Api::V1::PassiveSkillSerializer.new(object.passive_skill)
if object.passive_skill
object.passive_skill.attributes.slice('name', 'description')
end
end
def super_attack
Api::V1::SuperAttackSerializer.new(object.super_attack)
if object.super_attack
object.super_attack.attributes.slice('name', 'description')
end
end
def awaken_type
Api::V1::AwakenTypeSerializer.new(object.awaken_type)
object.awaken_type.attributes.slice('name').values.first
end
def dokkan_card
Api::V1::CardSerializer.new(object.dokkan_card)
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

View file

@ -1,3 +1,3 @@
class Api::V1::LinkSerializer < Api::V1::BaseSerializer
attributes :id, :name, :description
attributes :name, :description
end