Class: Hiiro::Tmux::Buffers
- Inherits:
-
Object
- Object
- Hiiro::Tmux::Buffers
- Includes:
- Enumerable
- Defined in:
- lib/hiiro/tmux/buffers.rb
Instance Attribute Summary collapse
-
#buffers ⇒ Object
readonly
Returns the value of attribute buffers.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_all ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #find_by_name(name) ⇒ Object
-
#initialize(buffers) ⇒ Buffers
constructor
A new instance of Buffers.
- #matching(pattern) ⇒ Object
- #name_map ⇒ Object
- #names ⇒ Object
- #size ⇒ Object (also: #count, #length)
Constructor Details
#initialize(buffers) ⇒ Buffers
Returns a new instance of Buffers.
16 17 18 |
# File 'lib/hiiro/tmux/buffers.rb', line 16 def initialize(buffers) @buffers = buffers end |
Instance Attribute Details
#buffers ⇒ Object (readonly)
Returns the value of attribute buffers.
14 15 16 |
# File 'lib/hiiro/tmux/buffers.rb', line 14 def buffers @buffers end |
Class Method Details
.fetch ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/hiiro/tmux/buffers.rb', line 6 def self.fetch output = `tmux list-buffers -F '#{Buffer::FORMAT}' 2>/dev/null` return new([]) if output.nil? || output.empty? buffers = output.each_line.map { |line| Buffer.from_format_line(line) }.compact new(buffers) end |
Instance Method Details
#clear_all ⇒ Object
53 54 55 |
# File 'lib/hiiro/tmux/buffers.rb', line 53 def clear_all buffers.each(&:delete) end |
#each(&block) ⇒ Object
20 21 22 |
# File 'lib/hiiro/tmux/buffers.rb', line 20 def each(&block) buffers.each(&block) end |
#empty? ⇒ Boolean
43 44 45 |
# File 'lib/hiiro/tmux/buffers.rb', line 43 def empty? buffers.empty? end |
#find_by_name(name) ⇒ Object
24 25 26 |
# File 'lib/hiiro/tmux/buffers.rb', line 24 def find_by_name(name) buffers.find { |b| b.name == name } end |
#matching(pattern) ⇒ Object
28 29 30 31 |
# File 'lib/hiiro/tmux/buffers.rb', line 28 def matching(pattern) regex = Regexp.new(pattern) self.class.new(buffers.select { |b| b.name =~ regex || b.sample =~ regex }) end |
#name_map ⇒ Object
37 38 39 40 41 |
# File 'lib/hiiro/tmux/buffers.rb', line 37 def name_map buffers.each_with_object({}) do |buffer, h| h[buffer.to_s] = buffer.name end end |
#names ⇒ Object
33 34 35 |
# File 'lib/hiiro/tmux/buffers.rb', line 33 def names buffers.map(&:name) end |
#size ⇒ Object Also known as: count, length
47 48 49 |
# File 'lib/hiiro/tmux/buffers.rb', line 47 def size buffers.size end |