Sha256: 499fa790d2ec28d9d98f99e8e3f16a32579f3b18622fc5a491d5605c6777121e

Contents?: true

Size: 1.43 KB

Versions: 28

Compression:

Stored size: 1.43 KB

Contents

module IcalImporter
  class LocalEvent
    class << self
      attr_accessor :class_attributes
    end

    @class_attributes = [
      :uid,
      :title,
      :description,
      :location,
      :start_date_time,
      :end_date_time,
      :utc,
      :date_exclusions,
      :recur_end_date,
      :recur_month_repeat_by,
      :recur_interval,
      :recur_interval_value,
      :recur_end_date,
      :recurrence_id,
      :all_day_event,
      :recurrence
    ]

    attr_accessor *class_attributes
    alias utc? utc
    alias all_day_event? all_day_event
    alias recurrence? recurrence

    DAYS = %w[sunday monday tuesday wednesday thursday friday saturday]
    DAYS.each do |day|
      class_attributes << "recur_week_#{day}".to_sym
      attr_accessor "recur_week_#{day}"
    end

    def initialize(attributes)
      self.attributes = attributes
      @date_exclusions ||= []
    end

    def get_attributes(list)
      raise ArgumentError, "Must be an Array" unless list.is_a? Array
      list.collect! { |e| e.to_s }
      attributes.select { |k,_| list.include? k.to_s }
    end

    def to_hash
      Hash[*self.class.class_attributes.collect { |attribute| [attribute.to_sym, send(attribute)] }.flatten(1)]
    end
    alias :attributes :to_hash

    def attributes=(attributes)
      attributes.each do |name, value|
        instance_variable_set "@#{name}", value if self.class.class_attributes.include? name.to_sym
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
ical_importer-0.5.1 lib/ical_importer/local_event.rb
ical_importer-0.5.0 lib/ical_importer/local_event.rb
ical_importer-0.4.0 lib/ical_importer/local_event.rb
ical_importer-0.3.0 lib/ical_importer/local_event.rb
ical_importer-0.2.0 lib/ical_importer/local_event.rb
ical_importer-0.1.3 lib/ical_importer/local_event.rb
ical_importer-0.1.2 lib/ical_importer/local_event.rb
ical_importer-0.1.1 lib/ical_importer/local_event.rb
ical_importer-0.1.0 lib/ical_importer/local_event.rb
ical_importer-0.0.19 lib/ical_importer/local_event.rb
ical_importer-0.0.18 lib/ical_importer/local_event.rb
ical_importer-0.0.17 lib/ical_importer/local_event.rb
ical_importer-0.0.16 lib/ical_importer/local_event.rb
ical_importer-0.0.15 lib/ical_importer/local_event.rb
ical_importer-0.0.14 lib/ical_importer/local_event.rb
ical_importer-0.0.13 lib/ical_importer/local_event.rb
ical_importer-0.0.12 lib/ical_importer/local_event.rb
ical_importer-0.0.11 lib/ical_importer/local_event.rb
ical_importer-0.0.10 lib/ical_importer/local_event.rb
ical_importer-0.0.9 lib/ical_importer/local_event.rb