Sha256: 3989a4a65e369e01911279c53e7688351e6249332f89730a5e03bc6c56b8f507

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 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
    ].freeze
    SCHED_ATTRIBUTES.each { |attribute| attr_accessor attribute }
    attr_accessor :client

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

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

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

    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

    def save
      if exists?
        update
      else
        create
      end
    end

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

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

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

    def destroy
      client.request("session/del", session_key: session_key)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sched-0.1.11 lib/sched/event.rb
sched-0.1.10 lib/sched/event.rb
sched-0.1.9 lib/sched/event.rb
sched-0.1.8 lib/sched/event.rb
sched-0.1.7 lib/sched/event.rb