Class: JLDrill::Definition

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefinition

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

#typesObject

Returns the value of attribute types.



15
16
17
# File 'lib/jldrill/model/items/edict/Definition.rb', line 15

def types
  @types
end

#valueObject

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

Returns:

  • (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_sObject



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