Class: JLDrill::Usage

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

Overview

Holds a collection of definitions that defines a typical usage for the word. It also holds an index number for the usage.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUsage

Returns a new instance of Usage.



13
14
15
16
# File 'lib/jldrill/model/items/edict/Usage.rb', line 13

def initialize
	@definitions = []
	@index = 0
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



10
11
12
# File 'lib/jldrill/model/items/edict/Usage.rb', line 10

def definitions
  @definitions
end

#indexObject

Returns the value of attribute index.



10
11
12
# File 'lib/jldrill/model/items/edict/Usage.rb', line 10

def index
  @index
end

#typesObject (readonly)

Returns the value of attribute types.



10
11
12
# File 'lib/jldrill/model/items/edict/Usage.rb', line 10

def types
  @types
end

Class Method Details

.create(string, index = 0) ⇒ Object



18
19
20
21
22
23
# File 'lib/jldrill/model/items/edict/Usage.rb', line 18

def Usage.create(string, index=0)
    usage = Usage.new
    usage.index = index
    usage.parse(string)
    usage
end

Instance Method Details

#allDefinitionsObject

Returns all the values for the definitions



42
43
44
45
46
47
48
# File 'lib/jldrill/model/items/edict/Usage.rb', line 42

def allDefinitions
	retVal = []
	@definitions.each do |defn|
		retVal.push defn.value unless defn.value == ""
	end
	retVal
end

#allTypesObject

Returns all the types in the definitions



33
34
35
36
37
38
39
# File 'lib/jldrill/model/items/edict/Usage.rb', line 33

def allTypes
	retVal = []
	@definitions.each do |defn|
		retVal += defn.types
	end
	retVal
end

#parse(string) ⇒ Object



25
26
27
28
29
30
# File 'lib/jldrill/model/items/edict/Usage.rb', line 25

def parse(string)
	string.split("/").each do |definition|
		defn = Definition.create(definition)
		@definitions.push(defn)
	end
end

#to_sObject



50
51
52
53
54
55
56
# File 'lib/jldrill/model/items/edict/Usage.rb', line 50

def to_s
    retVal = ""
    if index != 0
        retVal += "(" + index.to_s + ")"
    end
    retVal += @definitions.join("/")
end