teihitsu_training_cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/result.txt ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TeihitsuTrainingCli
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "teihitsu_training_cli/version"
5
+
6
+ require "csv"
7
+ require "thor"
8
+
9
+ # The class of quiz app
10
+ class Trng < Thor
11
+ package_name "Teihitsu Training CLI"
12
+
13
+ default_command :onyomi
14
+
15
+ method_option :start,
16
+ aliases: "-s",
17
+ desc: "Specify the index of the item you want to start"
18
+
19
+ # define the quiz item
20
+ class Item
21
+ def initialize(item)
22
+ (@index, @question, @_level, @answer, @alt_answer, @note) = item
23
+ @answers = [@answer, @alt_answer].compact
24
+ end
25
+
26
+ def quiz
27
+ puts "\n[#{@index}] #{@question}"
28
+ user_answer = $stdin.gets.chomp.strip
29
+ test user_answer
30
+ puts @note
31
+ end
32
+
33
+ def test(user_answer)
34
+ if @answers.include?(user_answer)
35
+ alt_answers = (@answers - [user_answer]).compact
36
+ puts "✅\n別答:#{alt_answers&.join}" unless alt_answers&.empty?
37
+ else
38
+ puts "❌\n正答:"
39
+ @answers.map { |e| puts e.to_s }
40
+ write_result
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def write_result
47
+ result = <<~"RESULT"
48
+ [#{@index}] #{@question}
49
+
50
+ 正答:
51
+ #{@answers.map(&:to_s)}
52
+
53
+ #{@note}
54
+
55
+ RESULT
56
+
57
+ File.open("result.txt", "a") do |io|
58
+ io.write(result)
59
+ end
60
+ end
61
+ end
62
+
63
+ desc "onyomi", "The questions will be taken from the onyomi section"
64
+ def onyomi
65
+ puts "©︎ 2022 Teihitsu Training"
66
+
67
+ start = options[:start] ? (options[:start].to_i - 1) : 0
68
+
69
+ items = CSV.read("problems/onyomi.csv")[start..]
70
+
71
+ items.each do |i|
72
+ item = Item.new(i)
73
+ item.quiz
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/teihitsu_training_cli/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "teihitsu_training_cli"
7
+ spec.version = TeihitsuTrainingCli::VERSION
8
+ spec.authors = ["Yuzuki Arai"]
9
+ spec.email = ["yudukikun5120@gmail.com"]
10
+
11
+ spec.summary = "teihitsu training for CLI"
12
+ spec.description = "A simple quiz application based on CLI."
13
+ spec.homepage = "https://rubygems.org/gems/teihitsu-training-cli"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.2"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/yudukikun5120/teihitsu-training-cli"
19
+ spec.metadata["changelog_uri"] = "https://github.com/yudukikun5120/teihitsu-training-cli/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.executables << "trng"
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_dependency "thor", "~> 1.2", ">= 1.2.1"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: teihitsu_training_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuzuki Arai
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.1
33
+ description: A simple quiz application based on CLI.
34
+ email:
35
+ - yudukikun5120@gmail.com
36
+ executables:
37
+ - teihitsu_training_cli
38
+ - trng
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - ".github/workflows/main.yml"
43
+ - ".gitignore"
44
+ - ".rubocop.yml"
45
+ - CHANGELOG.md
46
+ - CODE_OF_CONDUCT.md
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - exe/teihitsu_training_cli
55
+ - exe/trng
56
+ - lib/problems/onyomi.csv
57
+ - lib/result.txt
58
+ - lib/teihitsu_training_cli.rb
59
+ - lib/teihitsu_training_cli/version.rb
60
+ - teihitsu_training_cli.gemspec
61
+ homepage: https://rubygems.org/gems/teihitsu-training-cli
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://rubygems.org/gems/teihitsu-training-cli
66
+ source_code_uri: https://github.com/yudukikun5120/teihitsu-training-cli
67
+ changelog_uri: https://github.com/yudukikun5120/teihitsu-training-cli/CHANGELOG.md
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 3.0.2
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.3.10
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: teihitsu training for CLI
87
+ test_files: []