Class: JLDrill::Kana

Inherits:
Object
  • Object
show all
Defined in:
lib/jldrill/model/moji/Kana.rb

Overview

Represents a japanese phonetic character (either hiragana or katakana).

Constant Summary collapse

STROKES_RE =
/^S(\d+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(character, romaji, pronunciation, strokes, examples) ⇒ Kana

Returns a new instance of Kana.



14
15
16
17
18
19
20
# File 'lib/jldrill/model/moji/Kana.rb', line 14

def initialize(character, romaji, pronunciation, strokes, examples)
	@character = character
	@romaji = romaji
	@pronunciation = pronunciation
	@strokes = strokes
	@examples = examples
end

Instance Attribute Details

#characterObject (readonly)

Returns the value of attribute character.



11
12
13
# File 'lib/jldrill/model/moji/Kana.rb', line 11

def character
  @character
end

#examplesObject (readonly)

Returns the value of attribute examples.



11
12
13
# File 'lib/jldrill/model/moji/Kana.rb', line 11

def examples
  @examples
end

#pronunciationObject (readonly)

Returns the value of attribute pronunciation.



11
12
13
# File 'lib/jldrill/model/moji/Kana.rb', line 11

def pronunciation
  @pronunciation
end

#romajiObject (readonly)

Returns the value of attribute romaji.



11
12
13
# File 'lib/jldrill/model/moji/Kana.rb', line 11

def romaji
  @romaji
end

#strokesObject (readonly)

Returns the value of attribute strokes.



11
12
13
# File 'lib/jldrill/model/moji/Kana.rb', line 11

def strokes
  @strokes
end

Class Method Details

.getParts(string, separator) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/jldrill/model/moji/Kana.rb', line 22

def Kana.getParts(string, separator)
    retVal = nil
    if !string.nil?
        retVal = string.split(separator, -1)
    end
    retVal
end

.parse(string) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jldrill/model/moji/Kana.rb', line 34

def Kana.parse(string)
	entry = nil
	sections = Kana.getParts(string.chomp, "|")
	return if !Kana.validSections?(sections)
	character = sections[0]
	romaji = Kana.getParts(sections[2], "/")
	examples = Kana.getParts(sections[5], ",")
          pronunciation = sections[3]
	commands = Kana.getParts(sections[1], " ")
	strokes = nil
	commands.each do |command|
	    case command
	        when STROKES_RE
      				strokes = $1.to_i(10)
	    end
	end
	Kana.new(character, romaji, pronunciation, strokes, examples)
end

.validSections?(sections) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/jldrill/model/moji/Kana.rb', line 30

def Kana.validSections?(sections)
    !sections.nil? && sections.size == 6 && !sections[0].nil?
end

Instance Method Details

#eql?(kana) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/jldrill/model/moji/Kana.rb', line 53

def eql?(kana)
    @character.eql?(kana.character) &&
        @romaji.eql?(kana.romaji) &&
        @pronunciation.eql?(kana.pronunciation) &&
        @strokes.eql?(kana.strokes) &&
        @examples.eql?(kana.examples)
end

#to_sObject



61
62
63
64
65
66
67
68
# File 'lib/jldrill/model/moji/Kana.rb', line 61

def to_s
    retVal = @character
    retVal += " [" + @romaji.join(" ") + "]\n"
          retVal += @pronunciation + "\n\n"
    retVal += "Strokes: #{@strokes}\n\n"
          retVal += "English Examples: " + @examples.join(", ") + "\n"
    retVal
end