Class: ProductSpy::Host
- Inherits:
-
Object
- Object
- ProductSpy::Host
- Defined in:
- lib/product_spy/host.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#host_name ⇒ Object
readonly
Returns the value of attribute host_name.
Instance Method Summary collapse
- #build(type, pattern = nil, &block) ⇒ Object
-
#initialize(host_name) ⇒ Host
constructor
A new instance of Host.
- #make_pk(url) ⇒ Object
- #make_url(pk, options) ⇒ Object
- #parse(regex, pk_keys) ⇒ Object
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_name ⇒ Object (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, ) builder = @builder[[:type].to_sym] builder.get_url(pk) end |