Method: Fletcher::Model.identify

Defined in:
lib/fletcher/model.rb

.identify(url) ⇒ Object

Detect model by url

Fletcher::Model.identify("http://www.amazon.com/whatever") # => Flether::Models::Amazon


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fletcher/model.rb', line 6

def identify(url)
  if url =~ ::URI::regexp
    uri = ::URI::parse(url)
    host = uri.host
    matched_model = nil
    for model in Fletcher.model_classes
      #model_class =            
      matched_model = model if host =~ model.regexp 
    end 
    # raise ArgumentError, "Fletcher doesn't support #{host} yet." unless matched_model_class
    return matched_model
  else 
    raise ArgumentError, "not a url"
  end
end