Class: Icasework::Case

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

Overview

A Ruby representation of a case in iCasework

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Case

Returns a new instance of Case.



52
53
54
55
56
# File 'lib/icasework/case.rb', line 52

def initialize(hash)
  @hash = LazyHash.new(hash) do
    load_additional_data!
  end
end

Class Method Details

.create(params) ⇒ Object



18
19
20
21
22
23
# File 'lib/icasework/case.rb', line 18

def create(params)
  data = Icasework::Resource.create_case(params).data[:createcaseresponse]
  return nil unless data

  new(case_details: { case_id: data[:caseid] })
end

.where(params) ⇒ Object



11
12
13
14
15
16
# File 'lib/icasework/case.rb', line 11

def where(params)
  cases = Icasework::Resource.get_cases(params).data[:cases]
  return [] unless cases

  [cases[:case]].flatten.map { |data| new(case_data(data)) }
end

Instance Method Details

#[](key) ⇒ Object



62
63
64
# File 'lib/icasework/case.rb', line 62

def [](key)
  @hash[key]
end

#case_idObject



58
59
60
# File 'lib/icasework/case.rb', line 58

def case_id
  self[:case_details][:case_id]
end

#classificationsObject



66
67
68
# File 'lib/icasework/case.rb', line 66

def classifications
  @hash[:classifications].map { |c| Classification.new(c) }
end

#documentsObject



70
71
72
# File 'lib/icasework/case.rb', line 70

def documents
  @hash[:documents].map { |d| Document.new(d) }
end

#to_hObject



74
75
76
# File 'lib/icasework/case.rb', line 74

def to_h
  @hash.to_h
end