Sha256: baa41414a2e1bc7f3a8544508a78d518c5cb7e25b99fb88067ebc489c716c0b7

Contents?: true

Size: 654 Bytes

Versions: 6

Compression:

Stored size: 654 Bytes

Contents

module ModelXML
  class BlockParser

    class << self

      def parse &block
        raise "block required" unless block_given?
        parser = self.new
        parser.instance_eval &block
        parser.field_set
      end

    end

    attr_reader :field_set

    def initialize
      @field_set = []
    end

    def field *args

      # if the method is called without arguments, add it as a member of the field set
      if args.map(&:class) == [Symbol]
        @field_set << args[0]

      # otherwise add it as an array
      else
        @field_set << args
      end

    end

    def method_missing *args
      field *args
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
model_xml-1.0.14 lib/model_xml/block_parser.rb
model_xml-1.0.13 lib/model_xml/block_parser.rb
model_xml-1.0.12 lib/model_xml/block_parser.rb
model_xml-1.0.11 lib/model_xml/block_parser.rb
model_xml-1.0.9 lib/model_xml/block_parser.rb
model_xml-1.0.5 lib/model_xml/block_parser.rb