class Dgrid::API::Incident

Attributes

body[RW]
end_time[RW]
time[RW]

Public Class Methods

db_fields() click to toggle source
# File lib/dgrid/api/incident.rb, line 24
def self.db_fields
  %w(id name body time end_time)
end
new(options) click to toggle source
Calls superclass method
# 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
pluralized() click to toggle source
# File lib/dgrid/api/incident.rb, line 34
def self.pluralized
  'incidents'
end

Public Instance Methods

add_organization(organization) click to toggle source
# File lib/dgrid/api/incident.rb, line 58
def add_organization(organization)
  add_entity(organization)
end
add_person(person) click to toggle source
# File lib/dgrid/api/incident.rb, line 48
def add_person(person)
  add_entity(person)
end
add_place(place) click to toggle source
# File lib/dgrid/api/incident.rb, line 53
def add_place(place)
  add_entity(place)
end
add_time_to_hash(h, t,prefix) click to toggle source
# 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_hash() click to toggle source
# 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

Protected Instance Methods

fix_time_opts(orig_opts) click to toggle source
# File lib/dgrid/api/incident.rb, line 63
def fix_time_opts(orig_opts)
  split_time_opts, normal_opts = split_hash(orig_opts,[:time_time,:time_date,:end_time_time, :end_time_date])
  [:time, :end_time].each do |member|
     date_part = (member.to_s + "_date").to_sym
     time_part = (member.to_s + "_time").to_sym
     if (split_time_opts.include?(date_part)) 
         normal_opts[member] = split_time_opts[date_part] + " " + split_time_opts[time_part]
     end
  end
   normal_opts[:time] = DateTime::parse( normal_opts[:time]) if  normal_opts[:time].is_a?(String)
   normal_opts[:end_time] = DateTime::parse( normal_opts[:end_time]) if normal_opts[:end_time].is_a?(String)
   normal_opts
end