Class: DataMapper::YS::Scraper::Base

Inherits:
Object
  • Object
show all
Includes:
CachedAccessor
Defined in:
lib/dm-ys/scraper.rb

Overview

Base Scraper

Direct Known Subclasses

Composite, Page

Instance Method Summary collapse

Methods included from CachedAccessor

included

Constructor Details

#initialize(model, *args) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


54
55
56
57
58
# File 'lib/dm-ys/scraper.rb', line 54

def initialize(model, *args)
  raise ArgumentError, "missing model" unless model
  raise ArgumentError, "missing uri"   unless model.uri
  @model = model
end

Instance Method Details

#base_uriObject



71
72
73
# File 'lib/dm-ys/scraper.rb', line 71

def base_uri
  URI.parse(uri.split('?').first)
end

#countObject



63
64
65
# File 'lib/dm-ys/scraper.rb', line 63

def count
  records.size
end

#register_properties!Object



75
76
77
78
79
80
# File 'lib/dm-ys/scraper.rb', line 75

def register_properties!
  names.each do |name|
    type = String         # TODO
    @model.property name.intern, type
  end
end

#uriObject



67
68
69
# File 'lib/dm-ys/scraper.rb', line 67

def uri
  @uri || @model.uri.to_s.chomp('*')
end