Class: Rightstuff::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rightstuff/base.rb

Direct Known Subclasses

ArrayInstance, Server, ServerArray

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, item) ⇒ Base

Returns a new instance of Base.



27
28
29
30
# File 'lib/rightstuff/base.rb', line 27

def initialize( client, item )
  @client     = client
  @attributes = Base.extract_attributes( item )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



32
33
34
# File 'lib/rightstuff/base.rb', line 32

def method_missing( name, *args, &block )
  return @attributes[ name ]
end

Class Method Details

.extract_attributes(parent) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rightstuff/base.rb', line 14

def self.extract_attributes( parent )
  elements = parent.children.collect do | node |
    node.class == Nokogiri::XML::Element ? node : nil
  end
  elements.compact!
  elements.reduce( {} ) do | memo, element |
    name = element.name
    name.gsub!( /-/, '_' )
    memo[ name.intern ] = element.children[ 0 ].to_s
    memo
  end
end

.load_collection(client, doc) ⇒ Object



8
9
10
11
12
# File 'lib/rightstuff/base.rb', line 8

def self.load_collection( client, doc )
  doc.xpath( self.collection_xpath ).collect do | item |
    self.new( client, item )
  end
end