Class: JLDrill::StartsWith

Inherits:
Object
  • Object
show all
Defined in:
lib/jldrill/model/items/edict/ComparisonFunctors.rb

Constant Summary collapse

TO_A_RE =
Regexp.new("",nil,"u")

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ StartsWith

Returns a new instance of StartsWith.



7
8
9
10
11
12
# File 'lib/jldrill/model/items/edict/ComparisonFunctors.rb', line 7

def initialize(string)
    @startsWithArray = string.split(TO_A_RE)
    if @startsWithArray.nil?
        @startsWithArray = []
    end
end

Instance Method Details

#match(string) ⇒ Object



28
29
30
# File 'lib/jldrill/model/items/edict/ComparisonFunctors.rb', line 28

def match(string)
    return numCommonChars(string) == @startsWithArray.size
end

#numCommonChars(string) ⇒ Object

Returns the number of characters at the beginning of string that are also at the beginning of @startsWithArray



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jldrill/model/items/edict/ComparisonFunctors.rb', line 16

def numCommonChars(string)
    i = 0
    if !string.nil?
        a = string.split(TO_A_RE)
        while (i < a.size) && (i < @startsWithArray.size) &&
                (a[i] == @startsWithArray[i]) do
            i += 1
        end
    end
    return i
end