Class: CfScript::Output::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/cf_script/output/buffer.rb

Constant Summary collapse

ANSI_ESCAPE_SEQUENCE_REGEXP =
/\e\[(\d+)(;\d+)*m/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer = nil) ⇒ Buffer

Returns a new instance of Buffer.



7
8
9
# File 'lib/cf_script/output/buffer.rb', line 7

def initialize(buffer = nil)
  @raw = buffer
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



3
4
5
# File 'lib/cf_script/output/buffer.rb', line 3

def raw
  @raw
end

Instance Method Details

#[](arg) ⇒ Object



23
24
25
# File 'lib/cf_script/output/buffer.rb', line 23

def [](arg)
  content[arg]
end

#contains?(text) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/cf_script/output/buffer.rb', line 48

def contains?(text)
  matches?(/#{text}/)
end

#contentObject



11
12
13
# File 'lib/cf_script/output/buffer.rb', line 11

def content
  @clean_content ||= sanitize
end

#each_line(&block) ⇒ Object



27
28
29
# File 'lib/cf_script/output/buffer.rb', line 27

def each_line(&block)
  content.each_line(&block)
end

#from(pattern) ⇒ Object



31
32
33
# File 'lib/cf_script/output/buffer.rb', line 31

def from(pattern)
  lines_from(pattern).join("\n")
end

#last_lineObject



19
20
21
# File 'lib/cf_script/output/buffer.rb', line 19

def last_line
  lines.reject(&:empty?).last
end

#last_line_matches?(regexp) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/cf_script/output/buffer.rb', line 52

def last_line_matches?(regexp)
  last_line =~ regexp ? true : false
end

#linesObject



15
16
17
# File 'lib/cf_script/output/buffer.rb', line 15

def lines
  @clean_lines ||= sanitize_lines
end

#lines_from(pattern) ⇒ Object



35
36
37
38
# File 'lib/cf_script/output/buffer.rb', line 35

def lines_from(pattern)
  index = lines.find_index { |line| line =~ /#{pattern}/ }
  index ? lines[index..-1] : []
end

#match(regexp) ⇒ Object



40
41
42
# File 'lib/cf_script/output/buffer.rb', line 40

def match(regexp)
  content.match(regexp)
end

#matches?(regexp) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/cf_script/output/buffer.rb', line 44

def matches?(regexp)
  content =~ regexp ? true : false
end