在接下來的功能,我會需要一個可以幫我針對anki的modelName的不同,來進行指定的操作
所以現在會需要以下的規劃
因此會需要以下的interface
type OperatorGenerator interface {
GetByNote(note Note) (o Operator, err error)
}
type Operator interface {
Do() error
}
另外,也要針對目前的牌組設定相對應的Operator
我目前自己的牌組有三種
因此,也順應的產生了這三種struct
type NormalOperator struct {
Note Note
}
func (n *NormalOperator) Do() error {
//TODO implement me
panic("implement me")
}
type VerbOperator struct {
Note Note
}
func (v *VerbOperator) Do() error {
//TODO implement me
panic("implement me")
}
type AdjOperator struct {
Note Note
}
func (a *AdjOperator) Do() error {
//TODO implement me
panic("implement me")
}
以及相對應的測試
func (t *AnkiOperationSuite) Test_get_correct_modal_type_operator() {
note := Note{
ModelName: "Japanese (recognition&recall)",
}
generator := OperatorGenerate{}
normalOperator, _ := generator.GetByNote(note)
_, ok := normalOperator.(*NormalOperator)
t.True(ok, "type is not *NormalOperator")
note = Note{
ModelName: "Japanese (recognition&recall) 動詞篇",
}
generator = OperatorGenerate{}
verbOperator, _ := generator.GetByNote(note)
_, ok = verbOperator.(*VerbOperator)
t.True(ok, "type is not *VerbOperator")
note = Note{
ModelName: "Japanese (recognition&recall) 形容詞",
}
generator = OperatorGenerate{}
adjOperator, _ := generator.GetByNote(note)
_, ok = adjOperator.(*AdjOperator)
t.True(ok, "type is not *AdjOperator")
}
完整的程式碼如下
https://github.com/kevinyay945/anki-support/blob/v0.3.1