Module: WeddingRegistryScraper::Registries

Defined in:
lib/wedding_registry_scraper/registries.rb

Defined Under Namespace

Classes: CrateAndBarrel, HeathCeramics, PotteryBarn, Rei, WilliamsSonoma, Zola

Class Method Summary collapse

Class Method Details

.initialize_registry(url, options = {}) ⇒ Object



19
20
21
22
# File 'lib/wedding_registry_scraper/registries.rb', line 19

def initialize_registry(url, options={})
  klass = registry_class_from_url(url)
  klass ? klass.new(url, options) : nil
end

.registry_class_from_url(url) ⇒ Object



13
14
15
16
17
# File 'lib/wedding_registry_scraper/registries.rb', line 13

def registry_class_from_url(url)
  registry_classes.detect do |klass|
    /^https?:\/\/[^\/]*#{klass.domain}/.match(url)
  end
end

.registry_classesObject



3
4
5
6
7
8
9
10
11
# File 'lib/wedding_registry_scraper/registries.rb', line 3

def registry_classes
  @registry_classes ||= begin
    self.constants.map do |const|
      obj = self.const_get(const)
      obj if obj.is_a?(Class) && obj < WeddingRegistryScraper::Registry
    end.compact
  end
  @registry_classes
end