Class: ProductSpy::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/product_spy/host.rb

Defined Under Namespace

Classes: Builder, Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host_name) ⇒ Host

Returns a new instance of Host.



39
40
41
42
43
# File 'lib/product_spy/host.rb', line 39

def initialize(host_name)
  @host_name = host_name
  @parser = []
  @builder = {}
end

Instance Attribute Details

#host_nameObject (readonly)

Returns the value of attribute host_name.



37
38
39
# File 'lib/product_spy/host.rb', line 37

def host_name
  @host_name
end

Instance Method Details

#build(type, pattern = nil, &block) ⇒ Object



49
50
51
52
# File 'lib/product_spy/host.rb', line 49

def build(type, pattern = nil, &block)
  raise "No pattern and no block given" if pattern.nil? and not block_given?
  @builder[type.to_sym] = Builder.new(pattern, &block)
end

#make_pk(url) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/product_spy/host.rb', line 59

def make_pk(url)
  @parser.each do |parser|
    result = parser.get_pk(url)
    return result unless result.nil?
  end
  return nil
end

#make_url(pk, options) ⇒ Object



54
55
56
57
# File 'lib/product_spy/host.rb', line 54

def make_url(pk, options)
  builder = @builder[options[:type].to_sym]
  builder.get_url(pk)
end

#parse(regex, pk_keys) ⇒ Object



45
46
47
# File 'lib/product_spy/host.rb', line 45

def parse(regex, pk_keys)
  @parser << Parser.new(regex, pk_keys)
end