Start working on verbs
This commit is contained in:
parent
e59221b9ad
commit
25f2d260c7
96
src/verb.rb
Normal file
96
src/verb.rb
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
GUYS = {
|
||||||
|
"む" => { "a" => "ま", "i" => "み", "u" => "む", "e" => "め", "o" => "も" },
|
||||||
|
}
|
||||||
|
|
||||||
|
class KanaKanji
|
||||||
|
attr_reader :kana, :kanji
|
||||||
|
def initialize(kana, kanji=nil)
|
||||||
|
@kana = kana
|
||||||
|
@kanji = kanji || kana
|
||||||
|
end
|
||||||
|
|
||||||
|
def [] (index)
|
||||||
|
self.class.new kana[index], kanji[index]
|
||||||
|
end
|
||||||
|
|
||||||
|
def + (other)
|
||||||
|
self.class.new kana + other, kanji + other
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_character
|
||||||
|
GUYS[kana[-1]]
|
||||||
|
end
|
||||||
|
|
||||||
|
def all_but_last_character
|
||||||
|
self.class.new kana[0...-1], kanji[0...-1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Verb
|
||||||
|
attr_reader :dict_kanji, :dict_kana, :definition_english, :dict
|
||||||
|
|
||||||
|
def initialize(dict_kanji, dict_kana, definition_english)
|
||||||
|
@dict_kanji = dict_kanji || dict_kana
|
||||||
|
@dict_kana = dict_kana
|
||||||
|
@dict = KanaKanji.new dict_kana, dict_kanji
|
||||||
|
@definition_english = definition_english
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_character
|
||||||
|
dict.last_character
|
||||||
|
end
|
||||||
|
|
||||||
|
def all_but_last_character
|
||||||
|
dict.all_but_last_character
|
||||||
|
end
|
||||||
|
|
||||||
|
def ve
|
||||||
|
VerbExpression
|
||||||
|
end
|
||||||
|
|
||||||
|
def dictionary
|
||||||
|
dict
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class IchidanVerb < Verb
|
||||||
|
def long_form_present_positive
|
||||||
|
all_but_last_character + "ます"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class GodanVerb < Verb
|
||||||
|
def long_form_present_positive
|
||||||
|
all_but_last_character + last_character["i"] + "ます"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class SuruVerb < Verb
|
||||||
|
def long_form_present_positive
|
||||||
|
dict[..-3] + "します"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
見る = IchidanVerb.new("見る", "みる", "to look")
|
||||||
|
p 見る.dictionary.kanji
|
||||||
|
p 見る.dictionary.kana
|
||||||
|
p 見る.long_form_present_positive.kanji
|
||||||
|
p 見る.long_form_present_positive.kana
|
||||||
|
|
||||||
|
飲む = GodanVerb.new("飲む", "のむ", "to drink")
|
||||||
|
p 飲む.dictionary.kanji
|
||||||
|
p 飲む.dictionary.kana
|
||||||
|
p 飲む.long_form_present_positive.kanji
|
||||||
|
p 飲む.long_form_present_positive.kana
|
||||||
|
|
||||||
|
する = SuruVerb.new("する", "する", "to do")
|
||||||
|
p する.dictionary.kanji
|
||||||
|
p する.dictionary.kana
|
||||||
|
p する.long_form_present_positive.kanji
|
||||||
|
p する.long_form_present_positive.kana
|
||||||
|
|
||||||
|
勉強する = SuruVerb.new("勉強する", "べんきょうする", "to study")
|
||||||
|
p 勉強する.dictionary.kanji
|
||||||
|
p 勉強する.dictionary.kana
|
||||||
|
p 勉強する.long_form_present_positive.kanji
|
||||||
|
p 勉強する.long_form_present_positive.kana
|
Loading…
Reference in New Issue
Block a user