Files
danbooru/app/logical/iqdb/responses/collection.rb
r888888888 9e2c664a41 fixes #2130
2014-05-05 17:59:54 -07:00

27 lines
669 B
Ruby

module Iqdb
module Responses
class Collection
attr_reader :responses
delegate :each, :empty?, :any?, :to => :matches
def initialize(response_string)
@responses = response_string.split(/\n/).map do |string|
::Iqdb::Responses.const_get("Response_#{string[0..2]}").new(string[4..-1])
end
end
def matches
@matches ||= responses.select {|x| x.is_a?(Iqdb::Responses::Response_200) && x.score >= 90}
end
def errored?
errors.any?
end
def errors
@errors ||= responses.select {|x| x.is_a?(Iqdb::Responses::Error)}.map {|x| x.to_s}
end
end
end
end