module MetaHari
MetaHary will find product informations for a given product link. The information will be wrapped into an OpenStruct.
Example
¶ ↑
“`ruby product = MetaHari.spy
('example.com/product.html') “`
The AddressableFactory helper is trying to guess a URL out of a given string.
Example
“`ruby uri = MetaHari::Helpers::AddressableFactory.parse
('example.com/foo') # => example.com/foo “`
MetaHari
version
Constants
- VERSION
Public Class Methods
spy(uri, iteration = 0)
click to toggle source
# File lib/meta_hari.rb, line 23 def spy(uri, iteration = 0) uri = Helpers::AddressableFactory.parse uri.to_s spyglass = suitable_spyglass_instance uri, iteration spyglass.spy rescue RedirectNotification => redirect raise RedirectLoop.new, 'to many redirects' if redirect.iteration > 5 spy redirect.uri, redirect.iteration end
Private Class Methods
find_suitable_spyglass(uri)
click to toggle source
Finding a suitable spyglass for the given URL. If no suitable spyglass is found, the default spyglass (MetaHari::Spyglass::Base
) is returned.
# File lib/meta_hari.rb, line 42 def find_suitable_spyglass(uri) spyglasses = MetaHari::Spyglass.constants.map do |c| MetaHari::Spyglass.const_get(c) end spyglasses.select! { |spyglass| spyglass < MetaHari::Spyglass::Base } suitable_spyglass = spyglasses.find { |spyglass| spyglass.suitable? uri } suitable_spyglass || MetaHari::Spyglass::Base end
suitable_spyglass_instance(uri, iteration = 0)
click to toggle source
# File lib/meta_hari.rb, line 34 def suitable_spyglass_instance(uri, iteration = 0) klass = find_suitable_spyglass(uri) klass.new(uri, iteration) end