class CfScript::Output::Buffer
Constants
- ANSI_ESCAPE_SEQUENCE_REGEXP
Attributes
raw[R]
Public Class Methods
new(buffer = nil)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 7 def initialize(buffer = nil) @raw = buffer end
Public Instance Methods
[](arg)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 23 def [](arg) content[arg] end
contains?(text)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 48 def contains?(text) matches?(/#{text}/) end
content()
click to toggle source
# File lib/cf_script/output/buffer.rb, line 11 def content @clean_content ||= sanitize end
each_line(&block)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 27 def each_line(&block) content.each_line(&block) end
from(pattern)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 31 def from(pattern) lines_from(pattern).join("\n") end
last_line()
click to toggle source
# File lib/cf_script/output/buffer.rb, line 19 def last_line lines.reject(&:empty?).last end
last_line_matches?(regexp)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 52 def last_line_matches?(regexp) last_line =~ regexp ? true : false end
lines()
click to toggle source
# File lib/cf_script/output/buffer.rb, line 15 def lines @clean_lines ||= sanitize_lines end
lines_from(pattern)
click to toggle source
# 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)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 40 def match(regexp) content.match(regexp) end
matches?(regexp)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 44 def matches?(regexp) content =~ regexp ? true : false end
Private Instance Methods
sanitize()
click to toggle source
# File lib/cf_script/output/buffer.rb, line 58 def sanitize raw.gsub ANSI_ESCAPE_SEQUENCE_REGEXP, '' end
sanitize_line(line)
click to toggle source
# File lib/cf_script/output/buffer.rb, line 62 def sanitize_line(line) line.gsub! ANSI_ESCAPE_SEQUENCE_REGEXP, '' line.strip! line end
sanitize_lines()
click to toggle source
# File lib/cf_script/output/buffer.rb, line 68 def sanitize_lines raw.lines.map! do |line| sanitize_line(line) end end