Class: Exfuz::Query
- Inherits:
-
Object
- Object
- Exfuz::Query
- Defined in:
- lib/exfuz/query.rb
Constant Summary collapse
- MAX_UTF_8_BYTES =
3
Instance Attribute Summary collapse
-
#caret ⇒ Object
readonly
Returns the value of attribute caret.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #add(ch_or_chs) ⇒ Object
- #delete ⇒ Object
-
#initialize(caret) ⇒ Query
constructor
A new instance of Query.
- #left(direction = 1) ⇒ Object
- #right(direction = 1) ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(caret) ⇒ Query
Returns a new instance of Query.
12 13 14 15 16 17 |
# File 'lib/exfuz/query.rb', line 12 def initialize(caret) @chars = [] @line = '' @caret = caret @offset = caret[1] end |
Instance Attribute Details
#caret ⇒ Object (readonly)
Returns the value of attribute caret.
8 9 10 |
# File 'lib/exfuz/query.rb', line 8 def caret @caret end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
8 9 10 |
# File 'lib/exfuz/query.rb', line 8 def line @line end |
Instance Method Details
#add(ch_or_chs) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/exfuz/query.rb', line 23 def add(ch_or_chs) if ch_or_chs.instance_of?(Array) ch_or_chs.each do |ch| insert_at_caret(ch) right end elsif ch_or_chs.instance_of?(String) insert_at_caret(ch_or_chs) right end end |
#delete ⇒ Object
35 36 37 38 39 40 |
# File 'lib/exfuz/query.rb', line 35 def delete return if left_end?(@caret[1]) left remove_at_caret end |
#left(direction = 1) ⇒ Object
48 49 50 51 52 |
# File 'lib/exfuz/query.rb', line 48 def left(direction = 1) col = 0 col += 1 while direction > col && prev_caret end |
#right(direction = 1) ⇒ Object
42 43 44 45 46 |
# File 'lib/exfuz/query.rb', line 42 def right(direction = 1) col = 0 col += 1 while direction > col && next_caret end |
#text ⇒ Object
19 20 21 |
# File 'lib/exfuz/query.rb', line 19 def text @chars.join end |