Class: Jscon::Commands::MultiLine

Inherits:
Object
  • Object
show all
Defined in:
lib/jscon/commands/multi_line.rb

Class Method Summary collapse

Class Method Details

.bufferObject



34
35
36
# File 'lib/jscon/commands/multi_line.rb', line 34

def buffer
  @buffer ||= StringIO.new
end

.clear_bufferObject



38
39
40
41
# File 'lib/jscon/commands/multi_line.rb', line 38

def clear_buffer
  @buffer.close
  @buffer = nil
end

.ends_with_underscore(input) ⇒ Object



13
14
15
# File 'lib/jscon/commands/multi_line.rb', line 13

def ends_with_underscore(input)
  input =~ /\s_$/
end

.has_buffer?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/jscon/commands/multi_line.rb', line 30

def has_buffer?
  !!@buffer
end

.matches(input) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/jscon/commands/multi_line.rb', line 5

def matches(input)
  if has_buffer?
    true
  else
    ends_with_underscore(input)
  end
end

.run(input) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jscon/commands/multi_line.rb', line 17

def run(input)
  if ends_with_underscore(input)
    input = input.gsub(/\s_$/, '')
    buffer.puts(input)
    throw :skip_process_input
  else
    buffer.puts(input)
    total_input = buffer.string
    clear_buffer
    return total_input
  end
end