class Ellipses::Client::Parser
Constants
- Lexeme
- PATTERN
- Parsed
- SUBSTITUTIONS
Attributes
line[R]
Public Class Methods
match?(line)
click to toggle source
# File lib/ellipses/client/parser.rb, line 39 def match?(line) !line.match(PATTERN).nil? end
new(line)
click to toggle source
# File lib/ellipses/client/parser.rb, line 48 def initialize(line) @line = line end
parse(line)
click to toggle source
# File lib/ellipses/client/parser.rb, line 31 def parse(line) return unless (match = line.match(PATTERN)) parser = new(match[:directive]) Parsed.new lexemes: parser.(), prefix: match[:prefix] end
Public Instance Methods
call()
click to toggle source
# File lib/ellipses/client/parser.rb, line 52 def call Shellwords.split(preprocess(line)).slice_after('|').map do |group| group.pop if group.last == '|' Lexeme.from_strings(group) end end
Private Instance Methods
preprocess(rawline)
click to toggle source
# File lib/ellipses/client/parser.rb, line 66 def preprocess(rawline) rawline.strip.tap do |line| SUBSTITUTIONS.each { |pattern, replace| line.gsub!(pattern, replace) } line.strip! end end