Class: Zui::AsciiPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/zui/protocol.rb

Instance Method Summary collapse

Constructor Details

#initialize(min:, max:, first: nil, rest:) ⇒ AsciiPattern

Returns a new instance of AsciiPattern.



7
8
9
10
11
12
# File 'lib/zui/protocol.rb', line 7

def initialize(min:, max:, first: nil, rest:)
  @min = min
  @max = max
  @first = first
  @rest = rest
end

Instance Method Details

#match?(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/zui/protocol.rb', line 14

def match?(value)
  text = value.to_s
  return false if text.length < @min || text.length > @max
  return false if @first && !@first.include?(text[0])
  text.each_char.all? { |character| @rest.include?(character) }
end