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

View file

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