Class: JLDrill::Kana
- Inherits:
-
Object
- Object
- JLDrill::Kana
- 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
-
#character ⇒ Object
readonly
Returns the value of attribute character.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#pronunciation ⇒ Object
readonly
Returns the value of attribute pronunciation.
-
#romaji ⇒ Object
readonly
Returns the value of attribute romaji.
-
#strokes ⇒ Object
readonly
Returns the value of attribute strokes.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(kana) ⇒ Boolean
-
#initialize(character, romaji, pronunciation, strokes, examples) ⇒ Kana
constructor
A new instance of Kana.
- #to_s ⇒ Object
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
#character ⇒ Object (readonly)
Returns the value of attribute character.
11 12 13 |
# File 'lib/jldrill/model/moji/Kana.rb', line 11 def character @character end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
11 12 13 |
# File 'lib/jldrill/model/moji/Kana.rb', line 11 def examples @examples end |
#pronunciation ⇒ Object (readonly)
Returns the value of attribute pronunciation.
11 12 13 |
# File 'lib/jldrill/model/moji/Kana.rb', line 11 def pronunciation @pronunciation end |
#romaji ⇒ Object (readonly)
Returns the value of attribute romaji.
11 12 13 |
# File 'lib/jldrill/model/moji/Kana.rb', line 11 def romaji @romaji end |
#strokes ⇒ Object (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
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
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_s ⇒ Object
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 |