Sha256: dbbd83a5e6b9c51ee68e93c31bb9a552c0fe81500f27f8852b9f65bc4d2e60be

Contents?: true

Size: 904 Bytes

Versions: 4

Compression:

Stored size: 904 Bytes

Contents

require 'citrus'
require 'builder'

module Citrus
  class Match
    # Creates a Builder::XmlMarkup object from this match. Useful when
    # inspecting a nested match. The +xml+ argument may be a Hash of
    # Builder::XmlMarkup options.
    def to_markup(xml={})
      if xml.is_a?(Hash)
        opt = { :indent => 2 }.merge(xml)
        xml = Builder::XmlMarkup.new(opt)
        xml.instruct!
      end

      if matches.empty?
        xml.match("name" => name, "text" => text, "offset" => offset)
      else
        xml.match("name" => name, "text" => text, "offset" => offset) do
          matches.each {|m| m.to_markup(xml) }
        end
      end

      xml
    end

    # Returns the target of #to_markup which is an XML string unless another
    # target is specified in +opt+.
    def to_xml(opt={})
      to_markup(opt).target!
    end

    def inspect # :nodoc:
      to_xml
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
citrus-1.2.1 lib/citrus/debug.rb
citrus-1.2.0 lib/citrus/debug.rb
citrus-1.1.0 lib/citrus/debug.rb
citrus-1.0.0 lib/citrus/debug.rb