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.



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

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

Class Attribute Details

.attribute_namesObject (readonly)

Returns the value of attribute attribute_names.



6
7
8
# File 'lib/spidy/definition_object.rb', line 6

def attribute_names
  @attribute_names
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#to_hObject



19
20
21
# File 'lib/spidy/definition_object.rb', line 19

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

#to_sObject



15
16
17
# File 'lib/spidy/definition_object.rb', line 15

def to_s
  to_h.to_json
end