lib/signore/sig_finder.rb in signore-0.3.3 vs lib/signore/sig_finder.rb in signore-0.4.0
- old
+ new
@@ -1,23 +1,13 @@
+require_relative 'signature'
require_relative 'tags'
module Signore
- class SigFinder
- def self.find(sigs, random: Random.new, tags: Tags.new)
- new(sigs, random: random).find_tagged(tags: tags)
- end
+ module SigFinder
+ module_function
- def initialize(sigs, random: Random.new)
- @random = random
- @sigs = sigs
+ def find(sigs, random: Random.new, tags: Tags.new)
+ found = sigs.shuffle(random: random).find { |sig| tags.match?(sig.tags) }
+ found or Signature.new
end
-
- def find_tagged(tags: Tags.new)
- sigs
- .select { |sig| tags.required.all? { |tag| sig.tagged_with?(tag) } }
- .reject { |sig| tags.forbidden.any? { |tag| sig.tagged_with?(tag) } }
- .sample(random: random) or Signature.new
- end
-
- private_attr_reader :random, :sigs
end
end