Sha256: 972e5aeb6f8535ad3863d033b7f4c13298254eef0446b0c734e7e1ca1ec7c448

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'kanoko/application/convert/function'

module Kanoko
  module Application
    class Convert
      class ArgumentParser
        include Enumerable
        extend Forwardable
        def_delegators :@args, :each, :to_a

        attr_reader :options

        def initialize(args)
          @args, @options = ArgumentParser.parse args
        end

        def to_path
          map { |i| "/#{i.join('/')}" }.join
        end
        alias path to_path

        private

        class << self
          def parse(path)
            args = []
            options = []
            items = path.split('/')
            while item = items.shift
              id = item.to_sym
              if Function.list.include?(id)
                function = Function.new
                method = function.method(id)
                arg = items.shift(method.arity)
                options.concat method.call(*arg)
                args.push [id, *arg]
              end
            end
            [args, options]
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kanoko-0.1.3 lib/kanoko/application/convert/argument_parser.rb
kanoko-0.1.2 lib/kanoko/application/convert/argument_parser.rb
kanoko-0.1.1 lib/kanoko/application/convert/argument_parser.rb