Class: Evilution::CLI::Parser::StdinReader

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/cli/parser/stdin_reader.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, existing_files:) ⇒ StdinReader

Returns a new instance of StdinReader.



12
13
14
15
# File 'lib/evilution/cli/parser/stdin_reader.rb', line 12

def initialize(io, existing_files:)
  @io = io
  @existing_files = existing_files
end

Class Method Details

.call(io, existing_files:) ⇒ Object



8
9
10
# File 'lib/evilution/cli/parser/stdin_reader.rb', line 8

def self.call(io, existing_files:)
  new(io, existing_files: existing_files).call
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/evilution/cli/parser/stdin_reader.rb', line 17

def call
  return Result.new([], {}, "--stdin cannot be combined with positional file arguments") if @existing_files.any?

  lines = []
  @io.each_line do |line|
    line = line.strip
    lines << line unless line.empty?
  end
  files, ranges = Evilution::CLI::Parser::FileArgs.parse(lines)
  Result.new(files, ranges, nil)
end