Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- title : Test App CUI
- content : セレクトメニューの表示。データの入出力。今日の日付
- =end
- require 'date'
- class TestAppInfo
- def initialize(title, content)
- @title = title
- @content = content
- end
- attr_accessor :title, :content
- # 書式化
- def to_format(sep = "\n")
- "タイトル: #{@title}#{sep}内容: #{@content}#{sep}"
- end
- end
- class TestAppInfoManager
- def initialize
- @testapp_infos = {}
- end
- # データの入力
- def input_data
- testapp_info = TestAppInfo.new("", "")
- print "\n"
- print "キー: "
- key = gets.chomp
- print "タイトル: "
- testapp_info.title = gets.chomp
- print "内容: "
- testapp_info.content = gets.chomp
- @testapp_infos[key] = testapp_info
- end
- # データの出力
- def output_data
- puts "\n----------"
- @testapp_infos.each do |key, info|
- print info.to_format
- puts "----------"
- end
- end
- # 今日の日付の表示
- def print_date
- day = Date.today
- puts "\n----------"
- print "今日の日付 : #{day.to_s}"
- puts "\n----------"
- end
- # 処理選択画面の表示
- def select_menu
- loop do
- print "
- 1. データの入力
- 2. データの出力
- 3. 今日の日付の表示
- 9. 終了
- 番号を選んでください(1, 2, 3, 9): "
- select = gets.chomp
- case
- when '1' == select
- # データの入力
- input_data
- when '2' == select
- # データの出力
- output_data
- when '3' == select
- # 今日の日付の表示
- print_date
- when '9' == select
- # 終了
- break
- else
- # 処理選択画面に戻る
- end
- end
- end
- end
- testapp = TestAppInfoManager.new
- testapp.select_menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement