Class: Ifilter::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/ifilter/input.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = '') ⇒ Input

Returns a new instance of Input.



5
6
7
# File 'lib/ifilter/input.rb', line 5

def initialize(text = '')
  @text = text
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/ifilter/input.rb', line 3

def text
  @text
end

Instance Method Details

#<<(text) ⇒ Object



9
10
11
# File 'lib/ifilter/input.rb', line 9

def <<(text)
  @text << text
end

#backspace!Object



17
18
19
# File 'lib/ifilter/input.rb', line 17

def backspace!
  @text.chop!
end

#filter(array) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/ifilter/input.rb', line 31

def filter(array)
  array.each_with_object([]) do |str, outputs|
    regexp = self.to_regexp

    if !regexp.nil? && regexp =~ str
      outputs << str
    end
  end
end

#sizeObject



13
14
15
# File 'lib/ifilter/input.rb', line 13

def size
  @text.size
end

#to_regexpObject



25
26
27
28
29
# File 'lib/ifilter/input.rb', line 25

def to_regexp
  /#{@text}/i
rescue
  nil
end

#to_sObject



21
22
23
# File 'lib/ifilter/input.rb', line 21

def to_s
  @text
end