Class: Etapper::JournalEntry

Inherits:
EtapAbstract show all
Defined in:
lib/etapper/classes/journal_entry.rb

Direct Known Subclasses

Contact, Gift

Constant Summary collapse

TYPES =
{
  :note => 1,
  :contact => 2,
  :gift => 5,
  :pledge => 6,
  :payment => 7,
  :recurring_gift_schedule => 8,
  :recurring_gift => 9,
  :segmented_donation => 10,
  :soft_credit => 11,
  :disbursement => 12,
  :segmented_pledge => 13
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EtapAbstract

#==, #base, cname, etap_read_only, #method_missing, #new?, #save

Constructor Details

#initialize(base = nil) ⇒ JournalEntry

Set the ‘type’ field based on the real class name, if it wasn’t already



25
26
27
28
29
# File 'lib/etapper/classes/journal_entry.rb', line 25

def initialize(base = nil)
  super
  @type = self.class.symbolize
  @base.type ||= TYPES[@type]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Etapper::EtapAbstract

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



21
22
23
# File 'lib/etapper/classes/journal_entry.rb', line 21

def type
  @type
end

Class Method Details

.find(query) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/etapper/classes/journal_entry.rb', line 62

def self.find(query)
  case query
  when /\d+\.\d+\.\d+/  # "4310.0.2276679"
    g = client.send(getter, query)
    new(g) if g
  when Hash
    a = Account.find(query[:account])
    findByAccount(a)
  end
end

.findByAccount(account, options = {}) ⇒ Object

Retrieves a collection of gifts using getJournalEntries given an account



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/etapper/classes/journal_entry.rb', line 74

def self.findByAccount(, options={})
  p = Etapper::API::PagedJournalEntriesRequest.new(true, # clearCache
                                                   100,  # count
                                                   0,    # start
                                                   .ref,
                                                   nil,   # baseQuery
                                                   options[:endDate],
                                                   options[:startDate], 
                                                   [type])
  j = Etapper.client.getJournalEntries(p)
  if j.count > 0
    j.data.collect {|je| new(je)}
  else
    nil
  end
end

.getterObject

Returns the “get” method of the class as a symbol (e.g. :getGift)



58
59
60
# File 'lib/etapper/classes/journal_entry.rb', line 58

def self.getter
  "get#{cname}".to_sym
end

.symbolizeObject

Returns the name of the class as a symbol (e.g. :gift)



48
49
50
# File 'lib/etapper/classes/journal_entry.rb', line 48

def self.symbolize
  cname.symbolize
end

.typeObject

Returns the type number of the particular subclass (e.g. 5)



53
54
55
# File 'lib/etapper/classes/journal_entry.rb', line 53

def self.type
  TYPES[self.symbolize]
end

Instance Method Details

#accountObject

Associates the account that this gift belongs to.



37
38
39
# File 'lib/etapper/classes/journal_entry.rb', line 37

def 
  @account ||= Account.find(accountRef)
end

#account=(val) ⇒ Object

Sets the account that this gift belongs to.



42
43
44
45
# File 'lib/etapper/classes/journal_entry.rb', line 42

def account=(val)
  @account = val
  @base.accountRef = val.ref
end

#definedValuesObject



31
32
33
34
# File 'lib/etapper/classes/journal_entry.rb', line 31

def definedValues
  @base.definedValues ||= Etapper::API::ArrayOfDefinedValue.new
  @definedValues ||= Etapper::DefinedValueHash.new(base.definedValues)
end