module GroceryList
Constants
- VERSION
Attributes
items[R]
searcher[R]
Public Class Methods
search_all(items_source, searcher = IGASearcher.new)
click to toggle source
# File lib/grocery_list.rb, line 18 def search_all(items_source, searcher = IGASearcher.new) validate_input(items_source, searcher) @items = items_from_source(items_source) @searcher = searcher @items.each do |item| # For some odd reason, google chrome (and other browsers?) don't let # you open more than three tabs very quickly. So this sleep 0.2 works around # it. Not really sure what else I could do. It's ugly but it works... sleep 0.2 @searcher.search(item) end end
Private Class Methods
is_valid_source?(items_source)
click to toggle source
# File lib/grocery_list.rb, line 45 def is_valid_source?(items_source) @@source_type_tests.values.any? {|f| f.call(items_source)} end
items_from_source(items_source)
click to toggle source
# File lib/grocery_list.rb, line 37 def items_from_source(items_source) @@source_type_tests.each do |key, test| if test.call(items_source) return @@searchers[key].call(items_source) end end end
validate_input(items_source, searcher)
click to toggle source
# File lib/grocery_list.rb, line 32 def validate_input(items_source, searcher) raise ArgumentError, "isn't a valid source" unless is_valid_source? items_source raise ArgumentError, "searcher isn't a AbstractSearcher" unless searcher.kind_of? AbstractSearcher end