Sha256: d0d02c4c95327fccd11cfa90fbfeb7a7fa2789766fa9ae3131b2a361bf23a597

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

class RFlow
  module Components
    module IRC

      # The set of extensions to add capability to IRC data types
      module Extensions

        module IRCMessageExtension
          def self.extended(base_data)
            base_data.data_object ||= {'timestamp' => Time.now.xmlschema, 'prefix' => nil, 'command' => 'PRIVMSG', 'parameters' => []}
          end

          # Default accessors
          ['prefix', 'command', 'parameters'].each do |name|
            define_method name do |*args|
              data_object[name]
            end

            define_method :"#{name}=" do |*args|
              data_object[name] = args.first
            end
          end

          # Timestamp Accessors.  Note, the precision of the
          # XMLTimestamp is set to 9 digits, meaning that the time you
          # put in might be slightly different from the time you read
          # out.
          ['timestamp'].each do |name|
            define_method name do |*args|
              data_object[name] ? Time.xmlschema(data_object[name]) : nil
            end

            define_method :"#{name}=" do |*args|
              if args.first.is_a? Time
                data_object[name] = args.first.xmlschema(9)
              else
                data_object[name] = args.first
              end
            end
          end


        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rflow-components-irc-0.0.2 lib/rflow/components/irc/extensions.rb