Sha256: 8fb5ff294c4dd1f9c8e71da005f3bf5fe2ca2854f867814c3a431c5215022b84

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# takes sort_orders written in Ruby s-expressions and
# outputs EWS SortOrder XML
module Rews
  class SortOrder
    attr_reader :expr

    def initialize(expr)
      @expr=expr
    end

    def inspect
      "#{self.class}: #{@expr.inspect}"
    end
    
    def to_xml
      Xml::write_sort_order(expr)
    end

    module Xml
      module_function

      def write_sort_order(expr)
        xml = Builder::XmlMarkup.new
        xml.wsdl :SortOrder do
          write_expr(xml, expr)
        end
        xml.target!
      end

      def write_expr(xml, expr)
        expr.each do |field_order|
          write_field_order(xml, field_order)
        end
      end

      def write_field_order(xml, field_order)
        if field_order.is_a?(Array)
          xml.t :FieldOrder, :Order=>field_order[1] do
            write_field_uri(xml, field_order[0])
          end
        else
          xml.t :FieldOrder, field_order do
            write_field_uri(xml, field_order)
          end
        end
      end

      def write_field_uri(xml, field_uri)
        xml.t :FieldURI, :FieldURI=>field_uri
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rews-0.1.0 lib/rews/sort_order.rb