1
0
Fork 0

Merge branch 'atomaka/feature/importer-links' into 'development'

Add passive and link descriptions

Update the importer to add passive and link descriptions from atomaka data sources.

See merge request !12
This commit is contained in:
Andrew Tomaka 2015-10-25 11:43:04 -04:00
commit f50b344645

View file

@ -12,6 +12,10 @@ namespace :importer do
PaperTrail.whodunnit = 1 PaperTrail.whodunnit = 1
cards = JSON.parse(open('http://dbzv2.renzy.land/action/cards') { |f| f.read }) cards = JSON.parse(open('http://dbzv2.renzy.land/action/cards') { |f| f.read })
links = JSON.parse(open('http://api.dbzdokk.com/links') { |f| f.read })
links = Hash[links.map { |link| [link['name'], link['description']] }]
cards2 = JSON.parse(open('http://api.dbzdokk.com/characters') { |f| f.read })
passives = Hash[cards2.map { |card| [card['gameid'], card['passive']] }]
cards.each do |c| cards.each do |c|
@ -36,19 +40,24 @@ namespace :importer do
card['super_attack'] = SuperAttack card['super_attack'] = SuperAttack
.where( .where(
name: c['super_atk']['name'], name: c['super_atk']['name'],
description: c['super_atk']['desc']) description: c['super_atk']['desc']
)
.first_or_create .first_or_create
passive_skill_description = !c['passive_skill']['decsc'].blank? ? c['passive_skill']['decsc'] : passives[card['gameid']]
passive_skill = PassiveSkill passive_skill = PassiveSkill
.where( .where(
name: c['passive_skill']['name'], name: c['passive_skill']['name'],
description: c['passive_skill']['desc']) description: passive_skill_description
.first_or_initialize ).first_or_initialize
card['awaken_type'] = AwakenType.first card['awaken_type'] = AwakenType.first
card['passive_skill'] = passive_skill card['passive_skill'] = passive_skill
passive_skill.save(validate: false) passive_skill.save(validate: false)
card['links'] = Array.new card['links'] = Array.new
c['link_skill'].each do |link| c['link_skill'].each do |link|
card['links'] << Link.where(name: link).first_or_create card['links'] << Link.where(
name: link,
description: links[link]
).first_or_create
end end
card['hp_stat'] = Stat.create( card['hp_stat'] = Stat.create(