Sha256: 5be83a13003a7340db0d63f7f89272d5f94797d92ad59fcc98b144c1e986851a

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Dozuki
  module Mapper
    class Proxy
      attr_accessor :receiver, :from_node

      def initialize(receiver, node)
        self.receiver = receiver
        self.from_node = node
      end

      def string(attribute)
        self.receiver.send("#{attribute}=", from_node.string("./#{attribute}"))
      end

      def int(attribute)
        self.receiver.send("#{attribute}=", from_node.int("./#{attribute}"))
      end

      def date(attribute)
        self.receiver.send("#{attribute}=", from_node.date("./#{attribute}"))
      end

      def float(attribute)
        self.receiver.send("#{attribute}=", from_node.float("./#{attribute}"))
      end

      def boolean(attribute)
        self.receiver.send("#{attribute}=", from_node.boolean("./#{attribute}"))
      end

      def node(attribute, opts={})
        self.receiver.send("#{attribute}=", opts[:as].from_node(from_node.get("./#{attribute}")))
      end

      def each(attribute, opts={})
        from_node.each("./#{attribute}") do |node|
          receiver.send(opts[:to]) << opts[:as].from_node(node)
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dozuki-mapper-0.1.2 lib/dozuki-mapper/proxy.rb
dozuki-mapper-0.1.1 lib/dozuki-mapper/proxy.rb
dozuki-mapper-0.1.0 lib/dozuki-mapper/proxy.rb