Class: Sched::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/sched/event.rb

Constant Summary collapse

SCHED_ATTRIBUTES =
[
  # Required
  :session_key, :name, :session_start, :session_end, :session_type,
  # Optional
  :session_subtype, :description, :panelists, :url, :media_url, :venue,
  :address, :map, :tags, :active
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_key, client = nil) ⇒ Event

Returns a new instance of Event.



13
14
15
16
# File 'lib/sched/event.rb', line 13

def initialize(session_key, client = nil)
  @session_key = session_key
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



11
12
13
# File 'lib/sched/event.rb', line 11

def client
  @client
end

Instance Method Details

#configure(options = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/sched/event.rb', line 22

def configure(options = {})
  options.each do |key, value|
    send("#{key}=", value) if SCHED_ATTRIBUTES.include?(key)
  end
  self
end

#createObject



49
50
51
# File 'lib/sched/event.rb', line 49

def create
  client.request("session/add", data)
end

#dataObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sched/event.rb', line 29

def data
  data = {}
  SCHED_ATTRIBUTES.each do |attribute|
    next if get_attribute(attribute).nil?
    value = get_attribute(attribute)
    value = "Y" if value == true
    value = "N" if value == false
    data[attribute] = value
  end
  data
end

#destroyObject



61
62
63
64
# File 'lib/sched/event.rb', line 61

def destroy
  return unless exists?
  client.request("session/del", session_key: session_key)
end

#exists?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/sched/event.rb', line 57

def exists?
  client.events.map(&:session_key).include?(session_key) ? true : false
end

#get_attribute(key) ⇒ Object



18
19
20
# File 'lib/sched/event.rb', line 18

def get_attribute(key)
  send(key.to_s)
end

#saveObject



41
42
43
44
45
46
47
# File 'lib/sched/event.rb', line 41

def save
  if exists?
    update
  else
    create
  end
end

#updateObject



53
54
55
# File 'lib/sched/event.rb', line 53

def update
  client.request("session/mod", data)
end