Class: PivotalAPI::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pivotal-tracker-api/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/pivotal-tracker-api/base.rb', line 4

def initialize(attributes={})
  update_attributes(attributes)
end

Class Method Details

.from_json(json) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pivotal-tracker-api/base.rb', line 8

def self.from_json(json)
  object = nil
  if json.is_a?(Array)
    vals = []
    json.each { |val| vals << new(val) }
    object = vals
  else
    object = new(json)
  end
  object
end

Instance Method Details

#to_jsonObject



20
21
22
23
24
25
26
27
28
# File 'lib/pivotal-tracker-api/base.rb', line 20

def to_json
  hash = {}
  self.instance_variables.each do |var|
    key = var.to_s.delete('@')
    variable = self.instance_variable_get var
    hash[key.to_sym] = variable
  end
  hash.to_json
end