Class: JLDrill::Meaning

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

Constant Summary collapse

USAGE_DIVIDER_RE =
/\s?\(\d+\)\s?/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMeaning

Returns a new instance of Meaning.



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

def initialize()
    @types = []
    @usages = []
end

Instance Attribute Details

#definitionsObject (readonly)

Returns the value of attribute definitions.



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

def definitions
  @definitions
end

#typesObject (readonly)

Returns the value of attribute types.



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

def types
  @types
end

#usagesObject

Returns the value of attribute usages.



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

def usages
  @usages
end

Class Method Details

.create(string) ⇒ Object



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

def Meaning.create(string)
    meaning = Meaning.new
    meaning.parse(string)
    meaning
end

Instance Method Details

#allDefinitionsObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jldrill/model/items/edict/Meaning.rb', line 49

def allDefinitions
    retVal = []
    printUsages = @usages.size > 1
  @usages.each do |usage|
    defs = usage.allDefinitions
    if printUsages && !defs[0].nil?
      defs[0] = "(" + usage.index.to_s + ") " + defs[0]
    end
    retVal += defs
  end
  retVal
end

#allTypesObject



40
41
42
43
44
45
46
47
# File 'lib/jldrill/model/items/edict/Meaning.rb', line 40

def allTypes
    retVal = []
    retVal += @types
    @usages.each do |usage|
      retVal += usage.allTypes
    end
    retVal
end

#parse(string) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jldrill/model/items/edict/Meaning.rb', line 24

def parse(string)
    @usages = []
    parts = string.split(USAGE_DIVIDER_RE)
    i = 1
    parts.each do |usage|
        es = JLDrill::Usage.create(usage, i)
        if(es.allDefinitions.empty?)
        # Hack to get the tags at the beginning of the meaning
          @types += es.allTypes
        else
          @usages.push(es)
          i += 1
        end
    end
end

#to_sObject



62
63
64
65
66
67
68
69
# File 'lib/jldrill/model/items/edict/Meaning.rb', line 62

def to_s
  retVal = ""
  if types.size > 0
    retVal += "(" + @types.join(",") + ") "
  end
  retVal += @usages.join(" ") + "\n"
retVal
end