Class: JLDrill::Definition
- Inherits:
-
Object
- Object
- JLDrill::Definition
- Defined in:
- lib/jldrill/model/items/edict/Definition.rb
Overview
Holds a definition for an Edict entry. Each definition may have one or more type indicating its type of speach (verb, noun, etc)
Constant Summary collapse
- DEFINITION_RE =
/^(\(\S*\))\s?(.*)/
- SEPARATOR_RE =
/\)|,/
- COMMA_RE =
/[,]/
Instance Attribute Summary collapse
-
#types ⇒ Object
Returns the value of attribute types.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(definition) ⇒ Boolean
-
#initialize ⇒ Definition
constructor
A new instance of Definition.
- #parse(string) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Definition
Returns a new instance of Definition.
18 19 20 21 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 18 def initialize() @value = "" @types = [] end |
Instance Attribute Details
#types ⇒ Object
Returns the value of attribute types.
15 16 17 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 15 def types @types end |
#value ⇒ Object
Returns the value of attribute value.
15 16 17 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 15 def value @value end |
Class Method Details
.create(string) ⇒ Object
23 24 25 26 27 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 23 def Definition.create(string) definition = Definition.new definition.parse(string) definition end |
Instance Method Details
#eql?(definition) ⇒ Boolean
45 46 47 48 49 50 51 52 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 45 def eql?(definition) @value.eql?(definition.value) && (@types.size == definition.types.size) && @types.all? do |x| definition.types.find do |y| x.eql?(y) end end end |
#parse(string) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 29 def parse(string) @types = [] while string =~ DEFINITION_RE types = GrammarType.create($1) if(types.empty?) # There were no types in the parenthesis, so it must # be part of the definition. @value += $1 + " " else @types += types end string = $2 end @value += string.gsub(COMMA_RE, "\\,") end |
#to_s ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/jldrill/model/items/edict/Definition.rb', line 54 def to_s retVal = "" if @types.size > 0 retVal += "(" + @types.join(",") + ")" end retVal += @value retVal end |