hokkaido_dialect 0.2.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a21bdc78a82d2c65385bfeec21530a9715f6432283b3c6de8001792e145b12f
4
- data.tar.gz: 707a726e2e1c1b9d3ce90ca1bb8bdf8d6cd9aefc8af1baeccff40a13e1eae38e
3
+ metadata.gz: 114f73732e0eab167da397c90ac08af9424d7b9e5a5f4744656f5026f548d2d5
4
+ data.tar.gz: 3fc9c9d7dba92ccde821ed5bd6578fa4dd8c35944502aaa33762f5503ad333c7
5
5
  SHA512:
6
- metadata.gz: 1a3dd4924d32f06b7998b60c48324379bdff51d73e4cd72ea81a2445f701ea96726fdc67b588bbde3e1a9f3fd950e29acff598f97e1b7a3d1ba27104dd9c4762
7
- data.tar.gz: b7a07c79f2ae0397316ea74eca95d7cd8244d5f5852997f0b739b0225de7668e5e772b58be0d1c7fa74eefc82ea495d00b641d6acd18b343e5405004fed5ad3c
6
+ metadata.gz: 4dbc931fb1933e2867c9faa204307556f0574a258c0c2785df2bbd46eebea586a4939778ed84febba8060509753bdf5bc0dd5bf348612869fb722117b85d55cb
7
+ data.tar.gz: fdaf6d6cbb5c99ed6b9d55453a698748be1ea3c1b3207a0742a8a566441191a657caa1971b8cbee1c010fe8af3e194ad3f1888b4ab7c8ddd7799e75749146b30
data/README.md CHANGED
@@ -24,13 +24,24 @@ Start an interactive quiz in IRB:
24
24
  % irb
25
25
  irb(main):001> require 'hokkaido_dialect'
26
26
  => true
27
- irb(main):002> HokkaidoDialect::QuizGame.new.ask_and_check
28
- => 🦀🐻🐄💫✨
27
+ irb(main):002> HokkaidoDialect::QuizGame.play
29
28
  ```
30
29
 
31
- There will be multiple-choice questions on the correct usage of the Hokkaido dialect.
30
+ ### Play a quiz
32
31
 
33
- Enjoy the quiz and become familiar with the Hokkaido dialect!
32
+ ```ruby
33
+ # 3 random questions (default)
34
+ HokkaidoDialect::QuizGame.play
35
+
36
+ # Specify the number of questions
37
+ HokkaidoDialect::QuizGame.play(5)
38
+
39
+ # Play with all questions
40
+ HokkaidoDialect::QuizGame.all
41
+ ```
42
+
43
+ You will be asked multiple-choice questions on the correct usage of the Hokkaido dialect.
44
+ Enjoy the quiz and become familiar with the Hokkaido dialect! 🦀🐻🐄✨
34
45
 
35
46
  ## Development
36
47
 
@@ -27,8 +27,22 @@ module HokkaidoDialect
27
27
  ]
28
28
 
29
29
  class QuizGame
30
- def initialize
31
- question = QUESTIONS.sample
30
+ def self.play(number_of_questions = 3)
31
+ play_questions(QUESTIONS.sample(number_of_questions))
32
+ end
33
+
34
+ def self.all
35
+ play_questions(QUESTIONS.shuffle)
36
+ end
37
+
38
+ def self.play_questions(questions)
39
+ results = questions.map do |question|
40
+ new(question).ask_and_check
41
+ end
42
+ puts "#{questions.size}問中#{results.count(true)}問正解!"
43
+ end
44
+
45
+ def initialize(question = QUESTIONS.sample)
32
46
  wrong_usage = question[:wrong_usage]
33
47
  @dialect = question[:dialect]
34
48
  @correct_usage = question[:correct_usage]
@@ -36,26 +50,32 @@ module HokkaidoDialect
36
50
  end
37
51
 
38
52
  def ask_and_check
39
- puts ask
40
- print '番号を入力してください(1 or 2): '
41
- input = $stdin.gets.to_i
53
+ puts question_body
42
54
 
43
- unless [1, 2].include?(input)
44
- puts '無効な入力です!1または2を入力してください🐻'
45
- return
46
- end
55
+ input = input_until_valid
47
56
 
48
- if correct_answer?(input)
49
- puts '正解!🎉✨🦀'
50
- else
51
- puts '不正解…🐄'
57
+ correct_answer?(input).tap do |judgment|
58
+ puts judgment ? '正解!🎉✨🦀' : '不正解…🐄'
52
59
  end
53
60
  end
54
61
 
55
- def ask
62
+ def question_body
56
63
  "次の文章で正しい「#{@dialect}」の使い方はどっち?\n1. #{@choices[0]}\n2. #{@choices[1]}"
57
64
  end
58
65
 
66
+ def input_until_valid
67
+ loop do
68
+ print '番号を入力してください(1 or 2): '
69
+ input = $stdin.gets.to_i
70
+
71
+ if [1, 2].include?(input)
72
+ return input
73
+ end
74
+
75
+ puts '無効な入力です!1または2を入力してください🐻'
76
+ end
77
+ end
78
+
59
79
  def correct_answer?(input)
60
80
  index = input - 1
61
81
  @choices[index] == @correct_usage
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HokkaidoDialect
4
- VERSION = "0.2.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hokkaido_dialect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lemonade_37
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-05-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: 本物の北海道弁とエセ北海道弁を見分けるクイズです。
13
13
  executables: []
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  requirements: []
44
- rubygems_version: 3.6.2
44
+ rubygems_version: 3.6.9
45
45
  specification_version: 4
46
46
  summary: 本物の北海道弁とエセ北海道弁を見分けるクイズです。
47
47
  test_files: []