Class: CfScript::Output::Buffer
- Inherits:
-
Object
- Object
- CfScript::Output::Buffer
- Defined in:
- lib/cf_script/output/buffer.rb
Constant Summary collapse
- ANSI_ESCAPE_SEQUENCE_REGEXP =
/\e\[(\d+)(;\d+)*m/
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #[](arg) ⇒ Object
- #contains?(text) ⇒ Boolean
- #content ⇒ Object
- #each_line(&block) ⇒ Object
- #from(pattern) ⇒ Object
-
#initialize(buffer = nil) ⇒ Buffer
constructor
A new instance of Buffer.
- #last_line ⇒ Object
- #last_line_matches?(regexp) ⇒ Boolean
- #lines ⇒ Object
- #lines_from(pattern) ⇒ Object
- #match(regexp) ⇒ Object
- #matches?(regexp) ⇒ Boolean
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
#raw ⇒ Object (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
48 49 50 |
# File 'lib/cf_script/output/buffer.rb', line 48 def contains?(text) matches?(/#{text}/) end |
#content ⇒ Object
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_line ⇒ Object
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
52 53 54 |
# File 'lib/cf_script/output/buffer.rb', line 52 def last_line_matches?(regexp) last_line =~ regexp ? true : false end |
#lines ⇒ Object
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
44 45 46 |
# File 'lib/cf_script/output/buffer.rb', line 44 def matches?(regexp) content =~ regexp ? true : false end |