Sha256: bfe2c0734edbf545225c9828fe8976c6609ae5d4abbe4ddc04f5c79a8eb64bcf

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

module Sched
  class Event
    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,
      # WTF
      :event_key
    ]
    SCHED_ATTRIBUTES.each { |attribute| attr_accessor attribute }
    attr_accessor :client

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

    def event_key
      session_key
    end

    def event_key=(new_key)
      self.session_key = new_key
    end

    def get_attribute(key)
      self.send("#{key}")
    end

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

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

    def save
      if self.exists?
        self.update
      else
        self.create
      end
    end

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

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

    def exists?
      client.events.map{|e| e.session_key}.include?(self.session_key) ? true : false
    end

    def destroy
      self.client.request('session/del', {:session_key => self.session_key})
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sched-0.1.4 lib/sched/event.rb