Class: Internode::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/internode/resource.rb

Direct Known Subclasses

Account, Details, Service, Usage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
# File 'lib/internode/resource.rb', line 5

def initialize(options = {})
  @client = options.fetch(:client){ Internode.client }
  @path = options[:path]
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/internode/resource.rb', line 3

def client
  @client
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/internode/resource.rb', line 3

def path
  @path
end

Class Method Details

.content_attr(*names) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/internode/resource.rb', line 15

def content_attr(*names)
  names.each do |name|
    name = name.to_s
    method_name = name.gsub(/\W+/, "_")

    define_method(method_name) do
      content.at_css(name).text
    end
  end
end

Instance Method Details

#contentObject



10
11
12
# File 'lib/internode/resource.rb', line 10

def content
  @content ||= @client.get(path)
end