Created
October 7, 2014 14:58
-
-
Save TSFoster/9e035b8e2c704f5ff066 to your computer and use it in GitHub Desktop.
My (broken) solution for http://www.codewars.com/kata/520d623fdf58c68c6f00013e/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BatchItemProcessor | |
attr_accessor :processed_items | |
def initialize | |
reset | |
end | |
def process_items items | |
items.each do |item| | |
[email protected](item) | |
unless @processed_items.include? identifier | |
@processed_items.push identifier | |
yield item if @processor.call(item) | |
end | |
end | |
end | |
def reset | |
@processed_items = [] | |
@identifier = proc{|x| x} | |
@processor = proc{|x| true} | |
end | |
def identify identifier | |
@identifier = proc{|x| x.is_a?(Hash) ? x[identifier] : x.send(identifier)} | |
end | |
def should_process &block | |
@processor = block | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment