Class: Neovim::LineRange
- Inherits:
-
Object
- Object
- Neovim::LineRange
- Includes:
- Enumerable
- Defined in:
- lib/neovim/line_range.rb
Overview
Provide an enumerable interface for dealing with ranges of lines.
Instance Method Summary collapse
- #[](pos, len = nil) ⇒ Object (also: #slice)
- #[]=(*args) ⇒ Object
- #delete(index) ⇒ Object
- #each {|String| ... } ⇒ Array<String>
-
#initialize(buffer, _begin, _end) ⇒ LineRange
constructor
A new instance of LineRange.
- #replace(other) ⇒ Object
- #to_a ⇒ Array<String>
Constructor Details
#initialize(buffer, _begin, _end) ⇒ LineRange
Returns a new instance of LineRange.
6 7 8 9 10 |
# File 'lib/neovim/line_range.rb', line 6 def initialize(buffer, _begin, _end) @buffer = buffer @begin = _begin @end = _end end |
Instance Method Details
#[](index) ⇒ Object #[](range) ⇒ Object #[](index, length) ⇒ Object Also known as: slice
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/neovim/line_range.rb', line 39 def [](pos, len=nil) case pos when Range LineRange.new( @buffer, abs_line(pos.begin), abs_line(pos.exclude_end? ? pos.end - 1 : pos.end) ) else if len LineRange.new( @buffer, abs_line(pos), abs_line(pos + len -1) ) else @buffer.get_line(abs_line(pos)) end end end |
#[]=(index, string) ⇒ Object #[]=(index, length, strings) ⇒ Object #[]=(range, strings) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/neovim/line_range.rb', line 80 def []=(*args) *target, val = args pos, len = target case pos when Range @buffer.set_line_slice( abs_line(pos.begin), abs_line(pos.end), true, !pos.exclude_end?, val ) else if len @buffer.set_line_slice( abs_line(pos), abs_line(pos + len), true, false, val ) else @buffer.set_line(abs_line(pos), val) end end end |
#delete(index) ⇒ Object
115 116 117 |
# File 'lib/neovim/line_range.rb', line 115 def delete(index) @buffer.del_line(abs_line(index)) end |
#each {|String| ... } ⇒ Array<String>
19 20 21 |
# File 'lib/neovim/line_range.rb', line 19 def each(&block) to_a.each(&block) end |
#replace(other) ⇒ Object
109 110 111 112 |
# File 'lib/neovim/line_range.rb', line 109 def replace(other) self[0..-1] = other self end |
#to_a ⇒ Array<String>
13 14 15 |
# File 'lib/neovim/line_range.rb', line 13 def to_a @buffer.get_line_slice(@begin, @end, true, true) end |