weapons/summons: add promotion scopes and helpers
This commit is contained in:
parent
49e52fffb5
commit
e81c55905c
2 changed files with 48 additions and 0 deletions
|
|
@ -41,4 +41,28 @@ class Summon < ApplicationRecord
|
|||
def display_resource(summon)
|
||||
summon.name_en
|
||||
end
|
||||
|
||||
# Promotion scopes
|
||||
scope :by_promotion, ->(promotion) { where('? = ANY(promotions)', promotion) }
|
||||
scope :in_premium, -> { by_promotion(GranblueEnums::PROMOTIONS[:Premium]) }
|
||||
scope :in_classic, -> { by_promotion(GranblueEnums::PROMOTIONS[:Classic]) }
|
||||
scope :flash_exclusive, -> { by_promotion(GranblueEnums::PROMOTIONS[:Flash]).where.not('? = ANY(promotions)', GranblueEnums::PROMOTIONS[:Legend]) }
|
||||
scope :legend_exclusive, -> { by_promotion(GranblueEnums::PROMOTIONS[:Legend]).where.not('? = ANY(promotions)', GranblueEnums::PROMOTIONS[:Flash]) }
|
||||
|
||||
# Promotion helpers
|
||||
def flash?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Flash])
|
||||
end
|
||||
|
||||
def legend?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Legend])
|
||||
end
|
||||
|
||||
def premium?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Premium])
|
||||
end
|
||||
|
||||
def promotion_names
|
||||
promotions.filter_map { |p| GranblueEnums::PROMOTIONS.key(p)&.to_s }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -111,6 +111,30 @@ class Weapon < ApplicationRecord
|
|||
[4, 13, 17, 19].include?(series.to_i)
|
||||
end
|
||||
|
||||
# Promotion scopes
|
||||
scope :by_promotion, ->(promotion) { where('? = ANY(promotions)', promotion) }
|
||||
scope :in_premium, -> { by_promotion(GranblueEnums::PROMOTIONS[:Premium]) }
|
||||
scope :in_classic, -> { by_promotion(GranblueEnums::PROMOTIONS[:Classic]) }
|
||||
scope :flash_exclusive, -> { by_promotion(GranblueEnums::PROMOTIONS[:Flash]).where.not('? = ANY(promotions)', GranblueEnums::PROMOTIONS[:Legend]) }
|
||||
scope :legend_exclusive, -> { by_promotion(GranblueEnums::PROMOTIONS[:Legend]).where.not('? = ANY(promotions)', GranblueEnums::PROMOTIONS[:Flash]) }
|
||||
|
||||
# Promotion helpers
|
||||
def flash?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Flash])
|
||||
end
|
||||
|
||||
def legend?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Legend])
|
||||
end
|
||||
|
||||
def premium?
|
||||
promotions.include?(GranblueEnums::PROMOTIONS[:Premium])
|
||||
end
|
||||
|
||||
def promotion_names
|
||||
promotions.filter_map { |p| GranblueEnums::PROMOTIONS.key(p)&.to_s }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def series_slug
|
||||
|
|
|
|||
Loading…
Reference in a new issue