add promotions parsing to weapon and summon parsers
This commit is contained in:
parent
7aa0521ca4
commit
c1a5d62a12
3 changed files with 49 additions and 0 deletions
|
|
@ -216,6 +216,8 @@ module Granblue
|
|||
kamigame: hash['link_kamigame']
|
||||
}
|
||||
|
||||
info[:promotions] = promotions_from_obtain(hash['obtain'])
|
||||
|
||||
{
|
||||
info: info.compact
|
||||
# skills: skills.compact
|
||||
|
|
@ -232,6 +234,8 @@ module Granblue
|
|||
@summon.gamewith = hash[:links][:gamewith] if hash[:links].key?(:gamewith)
|
||||
@summon.kamigame = hash[:links][:kamigame] if hash[:links].key?(:kamigame)
|
||||
|
||||
@summon.promotions = hash[:promotions] if hash[:promotions].present?
|
||||
|
||||
if @summon.save
|
||||
ap "#{@summon.granblue_id}: Successfully saved info for #{@summon.wiki_en}" if @debug
|
||||
puts
|
||||
|
|
@ -246,6 +250,17 @@ module Granblue
|
|||
string ? GranblueWiki.rarities[string.upcase] : nil
|
||||
end
|
||||
|
||||
# Converts wiki obtain field to promotions array
|
||||
# @param obtain [String] Comma-separated obtain values like "premium,gala,flash"
|
||||
# @return [Array<Integer>] Array of promotion IDs
|
||||
def promotions_from_obtain(obtain)
|
||||
return [] if obtain.blank?
|
||||
|
||||
obtain.downcase.split(',').map(&:strip).filter_map do |value|
|
||||
Granblue::Parsers::Wiki.promotions[value]
|
||||
end.uniq.sort
|
||||
end
|
||||
|
||||
# Parses a date string into a Date object
|
||||
def parse_date(date_str)
|
||||
Date.parse(date_str) unless date_str.blank?
|
||||
|
|
|
|||
|
|
@ -222,6 +222,8 @@ module Granblue
|
|||
kamigame: hash['link_kamigame']
|
||||
}
|
||||
|
||||
info[:promotions] = promotions_from_obtain(hash['obtain'])
|
||||
|
||||
skills[:charge_attack] = {
|
||||
name: { en: hash['ougi_name'], ja: hash['jpougi_name'] },
|
||||
description: {
|
||||
|
|
@ -267,6 +269,8 @@ module Granblue
|
|||
@weapon.gamewith = hash[:links][:gamewith] if hash[:links].key?(:gamewith)
|
||||
@weapon.kamigame = hash[:links][:kamigame] if hash[:links].key?(:kamigame)
|
||||
|
||||
@weapon.promotions = hash[:promotions] if hash[:promotions].present?
|
||||
|
||||
if @weapon.save
|
||||
ap "#{@weapon.granblue_id}: Successfully saved info for #{@weapon.wiki_en}" if @debug
|
||||
puts
|
||||
|
|
@ -291,6 +295,17 @@ module Granblue
|
|||
string ? Granblue::Parsers::Wiki.bullets[string] : nil
|
||||
end
|
||||
|
||||
# Converts wiki obtain field to promotions array
|
||||
# @param obtain [String] Comma-separated obtain values like "premium,gala,flash"
|
||||
# @return [Array<Integer>] Array of promotion IDs
|
||||
def promotions_from_obtain(obtain)
|
||||
return [] if obtain.blank?
|
||||
|
||||
obtain.downcase.split(',').map(&:strip).filter_map do |value|
|
||||
Granblue::Parsers::Wiki.promotions[value]
|
||||
end.uniq.sort
|
||||
end
|
||||
|
||||
# Parses a date string into a Date object
|
||||
def parse_date(date_str)
|
||||
Date.parse(date_str) unless date_str.blank?
|
||||
|
|
|
|||
|
|
@ -107,6 +107,25 @@ module Granblue
|
|||
'holiday' => 6 # Holiday
|
||||
}.freeze
|
||||
|
||||
# Maps wiki |obtain= values to PROMOTIONS enum values for weapons/summons
|
||||
# Wiki uses comma-separated values like "premium,gala,flash"
|
||||
def self.promotions
|
||||
{
|
||||
'premium' => 1, # Premium
|
||||
'classic' => 2, # Classic
|
||||
'classic2' => 3, # Classic II
|
||||
'gala' => 4, # Flash (wiki uses "gala" for Flash Gala)
|
||||
'flash' => 4, # Flash (alternate)
|
||||
'legend' => 5, # Legend
|
||||
'valentine' => 6, # Valentine
|
||||
'summer' => 7, # Summer
|
||||
'halloween' => 8, # Halloween
|
||||
'holiday' => 9, # Holiday
|
||||
'collab' => 10, # Collab
|
||||
'formal' => 11 # Formal
|
||||
}.freeze
|
||||
end
|
||||
|
||||
def initialize(props: ['wikitext'], debug: false)
|
||||
@debug = debug
|
||||
@props = props.join('|')
|
||||
|
|
|
|||
Loading…
Reference in a new issue