Class: Pepin::Query

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Observable
Defined in:
lib/pepin/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(list, filter: GrepFilter) ⇒ Query

Returns a new instance of Query.



11
12
13
14
15
# File 'lib/pepin/query.rb', line 11

def initialize(list, filter: GrepFilter)
  @list   = list
  @string = ''
  @filter = filter.new
end

Instance Method Details

#add_char(ch) ⇒ Object



31
32
33
34
35
# File 'lib/pepin/query.rb', line 31

def add_char(ch)
  @string << ch

  notify_change
end

#clearObject



25
26
27
28
29
# File 'lib/pepin/query.rb', line 25

def clear
  @string.clear

  notify_change
end

#delete_ahead_from(pos) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/pepin/query.rb', line 63

def delete_ahead_from(pos)
  string_was = @string
  @string    = @string.to_s[0...pos]

  notify_change

  string_was.length - @string.length
end

#delete_behind_char_from(pos) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/pepin/query.rb', line 55

def delete_behind_char_from(pos)
  @string = @string[0...pos.pred] + @string[pos..-1]

  notify_change

  1
end

#delete_behind_from(pos) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/pepin/query.rb', line 37

def delete_behind_from(pos)
  string_was = @string
  @string    = @string.to_s[pos..-1]

  notify_change

  string_was.length - @string.length
end

#delete_behind_word_from(pos) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/pepin/query.rb', line 46

def delete_behind_word_from(pos)
  string_was = @string
  @string    = @string[0..pos.pred].split(/\b/)[0...-1].join + @string[pos..-1]

  notify_change

  string_was.length - @string.length
end

#patternObject



17
18
19
# File 'lib/pepin/query.rb', line 17

def pattern
  @filter.pattern(@string.strip)
end

#searchObject



21
22
23
# File 'lib/pepin/query.rb', line 21

def search
  @filter.select(@list, @string.strip)
end