Class: PrefixMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/prefix-machine.rb,
lib/prefix-machine/version.rb,
ext/prefix_machine/prefix_machine.c

Constant Summary collapse

VERSION =
'0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/prefix-machine.rb', line 5

def count
  @count
end

Instance Method Details

#guard!(str) ⇒ Object

Raises:

  • (NoMatchingPatternError)


7
8
9
# File 'lib/prefix-machine.rb', line 7

def guard!(str)
  raise NoMatchingPatternError.new('No Such Patterns') unless str =~ /[0-9a-z.]*/
end

#insert(rule) ⇒ Object Also known as: <<



11
12
13
14
15
# File 'lib/prefix-machine.rb', line 11

def insert(rule)
  s = rule.downcase
  guard!(s)
  trie_insert(s)
end

#match(str) ⇒ Object



17
18
19
20
21
# File 'lib/prefix-machine.rb', line 17

def match(str)
  s = str.downcase
  guard!(s)
  trie_match(s)
end