Files
danbooru/app/models/pixiv_ugoira_frame_data.rb
evazion ee4516f5fe searchable: refactor searchable_includes.
Pass searchable associations directly to search_attributes instead of
defining them separately in searchable_includes.
2020-12-16 23:57:07 -06:00

27 lines
576 B
Ruby

class PixivUgoiraFrameData < ApplicationRecord
belongs_to :post
serialize :data
before_validation :normalize_data, on: :create
def self.available_includes
[:post]
end
def self.search(params)
q = search_attributes(params, :id, :data, :content_type, :post)
q.apply_default_order(params)
end
def normalize_data
return if data.nil?
if data[0]["delay_msec"]
self.data = data.map.with_index do |datum, i|
filename = format("%06d.jpg", i)
{"delay" => datum["delay_msec"], "file" => filename}
end
end
end
end