Class: Rivendell::Import::CartFinder
- Inherits:
-
Object
- Object
- Rivendell::Import::CartFinder
- Defined in:
- lib/rivendell/import/cart_finder.rb
Defined Under Namespace
Instance Method Summary collapse
- #default_normalizer ⇒ Object
- #find_all_by_title(string, options = {}) ⇒ Object
- #find_by_title(string, options = {}) ⇒ Object
Instance Method Details
#default_normalizer ⇒ Object
13 14 15 16 17 |
# File 'lib/rivendell/import/cart_finder.rb', line 13 def default_normalizer Proc.new do |string| ActiveSupport::Multibyte::Chars.new(string).normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s.gsub(/[^a-z0-9]/," ").gsub(/[ ]+/," ") end end |
#find_all_by_title(string, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/rivendell/import/cart_finder.rb', line 4 def find_all_by_title(string, = {}) normalizer = .delete(:normalizer) || Proc.new { |id| id } string = normalizer.call(string) carts().select do |cart| normalizer.call(cart.title) == string end end |
#find_by_title(string, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/rivendell/import/cart_finder.rb', line 19 def find_by_title(string, = {}) matching_carts = find_all_by_title(string, ) if matching_carts.blank? matching_carts = find_all_by_title(string, .merge(:normalizer => default_normalizer)) end matching_carts.first if matching_carts.one? end |