Class: JLDrill::Deinflection::Match

Inherits:
Array
  • Object
show all
Defined in:
lib/jldrill/model/DeinflectionRules.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transform, history = nil) ⇒ Match

Returns a new instance of Match.



85
86
87
88
89
90
91
92
# File 'lib/jldrill/model/DeinflectionRules.rb', line 85

def initialize(transform, history=nil)
    if !history.nil?
        super(history)
    else
        super()
    end
    push(transform)
end

Class Method Details

.start(string) ⇒ Object



94
95
96
# File 'lib/jldrill/model/DeinflectionRules.rb', line 94

def Match.start(string)
    Match.new(Transform.start(string))
end

Instance Method Details

#apply(rule) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/jldrill/model/DeinflectionRules.rb', line 108

def apply(rule)
    retVal = nil
    if !last.nil? && !hasReason(rule)
        re = Regexp.new("(.*)#{rule.original}", nil)
        if re.match(last.dictionary)
            transform = Transform.new(last.dictionary, $1, rule)
            retVal = Match.new(transform, self)
        end
    end
    return retVal
end

#hasReason(rule) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/jldrill/model/DeinflectionRules.rb', line 98

def hasReason(rule)
    any? do |transform|
        if !transform.nil? && !transform.rule.nil?
            transform.rule.reason.eql?(rule.reason)
        else
            false
        end
    end
end

#to_sObject



130
131
132
# File 'lib/jldrill/model/DeinflectionRules.rb', line 130

def to_s
    transforms
end

#transformsObject



120
121
122
123
124
125
126
127
128
# File 'lib/jldrill/model/DeinflectionRules.rb', line 120

def transforms
    collect do |transform|
        if !transform.rule.nil?
            "(#{transform.root}#{transform.rule.original}) #{transform.rule.reason}: #{transform.dictionary}"
        else
            transform.dictionary
        end
    end.join(" > ")
end