Class: Vindsl::PrefixMatcher
- Inherits:
-
Object
- Object
- Vindsl::PrefixMatcher
- Defined in:
- lib/vindsl/prefix_matcher.rb
Instance Method Summary collapse
- #all_prefixes(str) ⇒ Object
- #find(prefix) ⇒ Object
- #first_prefix(prefix) ⇒ Object
-
#initialize(data) ⇒ PrefixMatcher
constructor
A new instance of PrefixMatcher.
Constructor Details
#initialize(data) ⇒ PrefixMatcher
Returns a new instance of PrefixMatcher.
3 4 5 |
# File 'lib/vindsl/prefix_matcher.rb', line 3 def initialize(data) @data = data end |
Instance Method Details
#all_prefixes(str) ⇒ Object
11 12 13 |
# File 'lib/vindsl/prefix_matcher.rb', line 11 def all_prefixes(str) str.length.times.map{|n| str[0..n]} end |
#find(prefix) ⇒ Object
7 8 9 |
# File 'lib/vindsl/prefix_matcher.rb', line 7 def find(prefix) @data[first_prefix prefix] end |
#first_prefix(prefix) ⇒ Object
15 16 17 18 19 |
# File 'lib/vindsl/prefix_matcher.rb', line 15 def first_prefix(prefix) all_prefixes(prefix).detect do |pfx| @data[pfx] end end |