Class: Blackbaud::BlackbaudObject

Inherits:
Object
  • Object
show all
Defined in:
lib/blackbaud-client/api/blackbaud_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BlackbaudObject

Returns a new instance of BlackbaudObject.



6
7
8
9
10
11
12
13
14
15
# File 'lib/blackbaud-client/api/blackbaud_object.rb', line 6

def initialize(options)
  @client ||= options.delete(:client)

  options.fetch(:values).each do |k,v|
    send("#{k}=".intern, v) if respond_to?("#{k}=".intern)
  end
rescue NoMethodError
  puts "NoMethodError: There is no method for one of the keys in your options: #{options}"
  return nil
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/blackbaud-client/api/blackbaud_object.rb', line 4

def client
  @client
end

Instance Method Details

#format_date(d) ⇒ Object



17
18
19
# File 'lib/blackbaud-client/api/blackbaud_object.rb', line 17

def format_date(d)
  DateTime.parse(d)
end

#to_hash(keys = nil) ⇒ Object Also known as: to_h



21
22
23
24
25
26
27
28
# File 'lib/blackbaud-client/api/blackbaud_object.rb', line 21

def to_hash(keys=nil)
  ivs = (keys ? (instance_variables & keys) : instance_variables)
  ivs -= [:@client]
  Hash[*
    ivs.map { |v|
    [v.to_s[1..-1].to_sym, instance_variable_get(v)]
  }.flatten]
end

#to_json(*args) ⇒ Object



30
31
32
# File 'lib/blackbaud-client/api/blackbaud_object.rb', line 30

def to_json(*args)
  JSON.generate(to_hash)
end