Class: JLDrill::DeinflectionRules
- Inherits:
-
Object
- Object
- JLDrill::DeinflectionRules
- Defined in:
- lib/jldrill/model/DeinflectionRules.rb
Overview
An array of Deinflection Rules.
Instance Attribute Summary collapse
-
#reasons ⇒ Object
readonly
Returns the value of attribute reasons.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize ⇒ DeinflectionRules
constructor
A new instance of DeinflectionRules.
- #match(string) ⇒ Object
- #parse(string) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ DeinflectionRules
Returns a new instance of DeinflectionRules.
141 142 143 144 145 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 141 def initialize @reasons = [] @rules = [] @readHeader = false end |
Instance Attribute Details
#reasons ⇒ Object (readonly)
Returns the value of attribute reasons.
139 140 141 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 139 def reasons @reasons end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
139 140 141 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 139 def rules @rules end |
Instance Method Details
#match(string) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 171 def match(string) retVal = [Deinflection::Match.start(string)] i = 0 while(i < retVal.size) do @rules.each do |rule| new = retVal[i].apply(rule) if !new.nil? && !retVal.any? do |match| match.last.dictionary.eql?(new.last.dictionary) end retVal.push(new) end end i += 1 end return retVal end |
#parse(string) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 147 def parse(string) if !@readHeader # The first line of the file must be discarded @readHeader = true else entry = Deinflection::Rule.parse(string, @reasons) if(!entry.nil?) @rules.push(entry) else reason = Deinflection::Reason.parse(string) if !reason.nil? @reasons.push(reason) else Context::Log::warning("JLDrill::DeinflectionRules", "Could not parse #{string}") end end end end |
#size ⇒ Object
167 168 169 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 167 def size return @rules.size + @reasons.size end |
#to_s ⇒ Object
188 189 190 |
# File 'lib/jldrill/model/DeinflectionRules.rb', line 188 def to_s self.join("\n") end |