85 lines
1.5 KiB
Ruby
85 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module FicTracker::Models::Light
|
|
class SearchInfo
|
|
def initialize(**data)
|
|
data.each do |k, v|
|
|
send(:"#{k}=", v) if respond_to?(:"#{k}=")
|
|
end
|
|
end
|
|
|
|
def with_language(lang)
|
|
self
|
|
end
|
|
|
|
def with_tag(tag)
|
|
self
|
|
end
|
|
|
|
def without_tag(tag)
|
|
self
|
|
end
|
|
|
|
def with_words(count)
|
|
self
|
|
end
|
|
|
|
def with_cursor(cursor)
|
|
self
|
|
end
|
|
|
|
def find_tags(category, search = nil)
|
|
raise ArgumentError, "No such category #{category.inspect}" unless @tags.key? category
|
|
|
|
tag_cat = @tags[category]
|
|
return if tag_cat[:freeform]
|
|
|
|
list = begin
|
|
if tag_cat[:list]
|
|
return tag_cat[:list] if search.nil?
|
|
return tag_cat[:list].select do |t|
|
|
case search
|
|
when Regex
|
|
t[:name] =~ search
|
|
when String
|
|
t[:name].downcase.include? search.downcase
|
|
else
|
|
false
|
|
end
|
|
end
|
|
end
|
|
return tag_cat[:search].call(search) if tag_cat[:search]
|
|
end
|
|
list.each do |t|
|
|
t[:id] ||= t[:name]
|
|
t[:category] ||= category
|
|
end
|
|
FicTracker::Models::Light::Tag.load list
|
|
end
|
|
|
|
def to_info_json
|
|
self.class.to_info_json
|
|
end
|
|
|
|
class << self
|
|
def from_search(data)
|
|
|
|
end
|
|
|
|
def to_info_json
|
|
|
|
end
|
|
|
|
protected
|
|
|
|
def tag_category(category, **params)
|
|
(@tags ||= {})[category] = params
|
|
end
|
|
|
|
def word_limits(*limits)
|
|
end
|
|
|
|
private
|
|
end
|
|
end
|
|
end
|