forked from yoshitokamizato/joint_dev_task
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagement.rb
More file actions
51 lines (42 loc) · 1.19 KB
/
management.rb
File metadata and controls
51 lines (42 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 課題の回答は task.rb をご利用下さい。
# 回答の出力を確認される際は,「ruby main.rb」をターミナルから実行して下さい。
require './task'
require './message'
class Management
TASK_RANGE = (1..20).freeze
@selected_numbers = []
def initialize
Message.info
Message.prompt_input
end
def prompt_input
input = gets.chomp
check_input(input)
end
def error_handling
Message.error
Message.info
Message.prompt_input
prompt_input
end
def check_input(input)
if input.match(/\A(\d+)\.+(\d+)\z/)
first = Regexp.last_match(1).to_i
last = Regexp.last_match(2).to_i
return error_handling unless first <= last && TASK_RANGE.include?(first) && TASK_RANGE.include?(last)
@selected_numbers = (first..last).to_a
else
@selected_numbers = input.scan(/\d+/)
return error_handling if @selected_numbers.empty?
@selected_numbers.each do |number|
return error_handling unless TASK_RANGE.include?(number.to_i)
end
end
end
def output_answer
@selected_numbers.each do |number|
Message.question_number(number)
eval("q#{number}", binding, 'task.rb')
end
end
end