Class: Spidy::DefinitionObject

Inherits:
Object
  • Object
show all
Defined in:
lib/spidy/definition_object.rb

Overview

An object that represents the scraper defined by define block.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, url) ⇒ DefinitionObject

Returns a new instance of DefinitionObject.



12
13
14
15
# File 'lib/spidy/definition_object.rb', line 12

def initialize(resource, url)
  @resource = resource
  @url = url
end

Class Attribute Details

.attribute_namesObject (readonly)

Returns the value of attribute attribute_names.



8
9
10
# File 'lib/spidy/definition_object.rb', line 8

def attribute_names
  @attribute_names
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'lib/spidy/definition_object.rb', line 10

def resource
  @resource
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/spidy/definition_object.rb', line 10

def url
  @url
end

Instance Method Details

#to_hObject



21
22
23
# File 'lib/spidy/definition_object.rb', line 21

def to_h
  self.class.attribute_names.to_h { |name| [name, send(name)] }
end

#to_sObject



17
18
19
# File 'lib/spidy/definition_object.rb', line 17

def to_s
  to_h.to_json
end