class PS::Object

Attributes

ps_reference_id[RW]

Public Class Methods

new(params = {}) click to toggle source
# File lib/ps/object.rb, line 5
def initialize(params = {})
  set_attributes(params)
end

Private Class Methods

instantiate_object() click to toggle source
# File lib/ps/object.rb, line 43
def self.instantiate_object
  Proc.new { |response| PS::Util.instantiate_ps_objects(response.ps_object) }
end

Public Instance Methods

attributes() click to toggle source
# File lib/ps/object.rb, line 9
def attributes
  attributes_hash = {}
  self.instance_variables.each do |v|
    attributes_hash[v[1..-1].to_sym] = self.send(v[1..-1])
  end
  attributes_hash
end
set_attributes(params={}) click to toggle source
# File lib/ps/object.rb, line 17
def set_attributes(params={})
  params.each do |k, v|
    next unless self.class.method_defined?(k)
    instance_variable_set("@#{k}", v)
  end
end
to_s() click to toggle source
# File lib/ps/object.rb, line 24
def to_s
  attrs = self.attributes.to_a.map { |k_v| 
    case k_v[1]
      when Fixnum
        "#{k_v[0]}: #{k_v[1]}" 
      when String || Time
        "#{k_v[0]}: '#{k_v[1]}'" unless k_v[1].empty?
    end

  }.delete_if(&:nil?).join(", ")
  "#<#{self.class} #{attrs}>"
end

Private Instance Methods

update_self() click to toggle source

this block will fail if more than one PS::Object is returned.

# File lib/ps/object.rb, line 39
def update_self
  Proc.new { |response|  set_attributes(response.ps_object) }
end