Sha256: 2e96db36f2da0c960725153678302968b99bc49c7b783a8db4b67495e3b53e2d

Contents?: true

Size: 661 Bytes

Versions: 4

Compression:

Stored size: 661 Bytes

Contents

module Space
  class Action
    class Parser
      attr_reader :names, :line

      def initialize(names)
        @names = names
      end

      def parse(line)
        @line = line
        scope = parse_scope
        command = parse_command
        [scope, command]
      end

      private

        def parse_scope
          scope = []
          pattern = /^(#{names.join('|')}|\d+)\s*/
          line.gsub!(pattern) { |repo| scope << repo.strip; '' } while line =~ pattern
          line.strip!
          scope unless scope.empty?
        end

        def parse_command
          line.strip
          line unless line.empty?
        end
    end
  end
end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
space-0.0.9 lib/space/action/parser.rb
space-0.0.8 lib/space/action/parser.rb
space-0.0.7 lib/space/action/parser.rb
space-0.0.6 lib/space/action/parser.rb