module Icalendar::DateProp::ClassMethods

This is made a sub-module just so it can be added as class methods rather than instance methods.

Public Instance Methods

date_property(dp, alias_name = nil) click to toggle source
# File lib/icalendar/helpers.rb, line 38
      def date_property(dp, alias_name = nil)
        dp = "#{dp}".strip.downcase
        getter = dp
        setter = "#{dp}="
        query = "#{dp}?"

        unless instance_methods.include? getter
          code = <<-code
            def #{getter}(*a)
              if a.empty?
                @properties[#{dp.upcase}]
              else
                self.#{dp} = a.first
              end 
            end
          code

          module_eval code
        end
           
        unless instance_methods.include? setter
          code = <<-code
            def #{setter} a
              @properties[#{dp.upcase}] = a
            end
          code

          module_eval code
        end

        unless instance_methods.include? query
          code = <<-code
            def #{query}
              @properties.has_key?(#{dp.upcase})
            end
          code

          module_eval code
        end

        # Define the getter
        getter = "get#{property.to_s.capitalize}"
        define_method(getter.to_sym) do
          puts "inside getting..."
          getDateProperty(property.to_s.upcase)  
        end
        
        # Define the setter
        setter = "set#{property.to_s.capitalize}"        
        define_method(setter.to_sym) do |*params|
          date = params[0]
          utc = params[1]
          puts "inside setting..."
          setDateProperty(property.to_s.upcase, date, utc)
        end

        # Create aliases if a name was specified
#         if not aliasName.nil?
#           gasym = "get#{aliasName.to_s.capitalize}".to_sym 
#           gsym = getter.to_sym
#           alias gasym gsym 
          
#           sasym = "set#{aliasName.to_s.capitalize}".to_sym 
#           ssym = setter.to_sym
#           alias sasym ssym 
#        end
      end