Class: JLDrill::DictionaryEntry

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

Overview

A word in the dictionary. It has a reference to a DictionaryLocation and may have a cached Meaning

Constant Summary collapse

Headings =
[["bothKanji", "Kanji", 90],
["reading", "Reading", 130],
["toVocab.definitions", "Meaning", 230]]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDictionaryEntry

Returns a new instance of DictionaryEntry.



18
19
20
21
22
23
24
25
26
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 18

def initialize
    @kanji = ""
    @simplified = ""
    @reading = ""
    @dictionary = nil
    @position = -1
    @vocab = nil
    @relevance = 0 
end

Instance Attribute Details

#dictionaryObject

Returns the value of attribute dictionary.



13
14
15
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 13

def dictionary
  @dictionary
end

#kanjiObject

Returns the value of attribute kanji.



13
14
15
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 13

def kanji
  @kanji
end

#positionObject

Returns the value of attribute position.



13
14
15
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 13

def position
  @position
end

#readingObject

Returns the value of attribute reading.



13
14
15
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 13

def reading
  @reading
end

#relevanceObject

Returns the value of attribute relevance.



13
14
15
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 13

def relevance
  @relevance
end

#simplifiedObject

Returns the value of attribute simplified.



13
14
15
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 13

def simplified
  @simplified
end

Instance Method Details

#bothKanjiObject



34
35
36
37
38
39
40
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 34

def bothKanji
    retVal = @kanji
    if !@simplified.empty?
        retVal += "/#{@simplified}"
    end
    return retVal
end

#kanjiEql?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

def kanjiEql?(key)
    retVal = false
    if !@kanji.empty?
        retVal |= @kanji.eql?(key)
    end
    if !@simplified.empty?
        retVal |= @simplified.eql?(key)
    end
    return retVal
end

#kanjiStartsWith?(key) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
101
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 92

def kanjiStartsWith?(key)
    retVal = false
    if !@kanji.empty?
        retVal |= @kanji.start_with?(key)
    end
    if !@simplified.empty?
        retVal |= @simplified.start_with?(key)
    end
    return retVal
end

#keyStartsWithKanji?(key) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
85
86
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 77

def keyStartsWithKanji?(key)
    retVal = false
    if !@kanji.empty?
        retVal |= key.start_with?(@kanji)
    end
    if !@simplified.empty?
        retVal |= key.start_with?(@simplified)
    end
    return retVal
end

#keyStartsWithReading?(key) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 73

def keyStartsWithReading?(key)
    return key.start_with?(@reading)
end

#readingEql?(key) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 58

def readingEql?(key)
    return @reading.eql?(key)
end

#readingStartsWith?(key) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 88

def readingStartsWith?(key)
    return @reading.start_with?(key)
end

#startsWith?(key) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 103

def startsWith?(key)
    return readingStartsWith(key) || kanjiStartsWith(key)
end

#to_sObject



54
55
56
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 54

def to_s
    return @dictionary.lines[@position]
end

#toMeaningObject



49
50
51
52
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 49

def toMeaning
    @meaning = @dictionary.getMeaning(@position)
    return @meaning
end

#toVocabObject



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

def toVocab
    if @vocab.nil?
        @vocab = @dictionary.getVocab(@position)
    end
    return @vocab
end

#valid?Boolean

The DictionaryEntry is valid if there is a reading. There doesn’t need to be a kanji

Returns:

  • (Boolean)


30
31
32
# File 'lib/jldrill/model/items/DictionaryEntry.rb', line 30

def valid?
    return !@reading.empty?
end