Class: Dgrid::API::Incident

Inherits:
NamedEntity show all
Defined in:
lib/dgrid/api/incident.rb

Instance Attribute Summary collapse

Attributes inherited from NamedEntity

#name

Attributes inherited from Entity

#description, #id, #workspaces

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#add_entity, #add_workspace, #attach, #connection, #first_workspace, #in_workspace?, #link_to, #new_record?, singular, #type, type

Methods included from SetMembersFromHash

#change_string_keys_to_symbol_keys, #set_members_from_hash, #split_hash

Methods included from Dgrid::ArgumentValidation

included

Constructor Details

#initialize(options) ⇒ Incident

Returns a new instance of Incident.



17
18
19
20
21
22
# File 'lib/dgrid/api/incident.rb', line 17

def initialize(options)
  parent_opts, my_opts = split_hash(options,[:name, :description])
  super(parent_opts)
  member_opts = fix_time_opts(my_opts)
  set_members_from_hash(member_opts)
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/dgrid/api/incident.rb', line 4

def body
  @body
end

#end_timeObject

Returns the value of attribute end_time.



4
5
6
# File 'lib/dgrid/api/incident.rb', line 4

def end_time
  @end_time
end

#timeObject

Returns the value of attribute time.



4
5
6
# File 'lib/dgrid/api/incident.rb', line 4

def time
  @time
end

Class Method Details

.db_fieldsObject



24
25
26
# File 'lib/dgrid/api/incident.rb', line 24

def self.db_fields
  %w(id name body time end_time)
end

.pluralizedObject



34
35
36
# File 'lib/dgrid/api/incident.rb', line 34

def self.pluralized
  'incidents'
end

Instance Method Details

#add_organization(organization) ⇒ Object



58
59
60
# File 'lib/dgrid/api/incident.rb', line 58

def add_organization(organization)
  add_entity(organization)
end

#add_person(person) ⇒ Object



48
49
50
# File 'lib/dgrid/api/incident.rb', line 48

def add_person(person)
  add_entity(person)
end

#add_place(place) ⇒ Object



53
54
55
# File 'lib/dgrid/api/incident.rb', line 53

def add_place(place)
  add_entity(place)
end

#add_time_to_hash(h, t, prefix) ⇒ Object



28
29
30
31
32
# File 'lib/dgrid/api/incident.rb', line 28

def add_time_to_hash(h, t,prefix)
  h["#{prefix}_time".to_sym]  = t.strftime("%H:%M")
  h["#{prefix}_date".to_sym] = t.strftime("%Y-%m-%d")
  h
end

#to_hashObject



38
39
40
41
42
43
44
45
# File 'lib/dgrid/api/incident.rb', line 38

def to_hash
  h = { :name => name,
        :body => body
      }
  add_time_to_hash(h,time,'time') unless time.nil?
  add_time_to_hash(h,end_time,'end_time') unless end_time.nil?
  h
end