Class: Rightstuff::Base

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

Direct Known Subclasses

Server

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, item) ⇒ Base

Returns a new instance of Base.



60
61
62
63
# File 'lib/rightstuff.rb', line 60

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



65
66
67
# File 'lib/rightstuff.rb', line 65

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

Class Method Details

.extract_attributes(parent) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rightstuff.rb', line 47

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



41
42
43
44
45
# File 'lib/rightstuff.rb', line 41

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