Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. =begin
  2. title : Test App CUI
  3. content : セレクトメニューの表示。データの入出力。今日の日付
  4. =end
  5. require 'date'
  6.  
  7. class TestAppInfo
  8. def initialize(title, content)
  9. @title = title
  10. @content = content
  11. end
  12.  
  13. attr_accessor :title, :content
  14.  
  15. # 書式化
  16. def to_format(sep = "\n")
  17. "タイトル: #{@title}#{sep}内容: #{@content}#{sep}"
  18. end
  19. end
  20.  
  21. class TestAppInfoManager
  22. def initialize
  23. @testapp_infos = {}
  24. end
  25.  
  26. # データの入力
  27. def input_data
  28. testapp_info = TestAppInfo.new("", "")
  29. print "\n"
  30. print "キー: "
  31. key = gets.chomp
  32. print "タイトル: "
  33. testapp_info.title = gets.chomp
  34. print "内容: "
  35. testapp_info.content = gets.chomp
  36.  
  37. @testapp_infos[key] = testapp_info
  38. end
  39.  
  40. # データの出力
  41. def output_data
  42. puts "\n----------"
  43. @testapp_infos.each do |key, info|
  44. print info.to_format
  45. puts "----------"
  46. end
  47. end
  48.  
  49. # 今日の日付の表示
  50. def print_date
  51. day = Date.today
  52. puts "\n----------"
  53. print "今日の日付 : #{day.to_s}"
  54. puts "\n----------"
  55. end
  56.  
  57. # 処理選択画面の表示
  58. def select_menu
  59. loop do
  60. print "
  61. 1. データの入力
  62. 2. データの出力
  63. 3. 今日の日付の表示
  64. 9. 終了
  65. 番号を選んでください(1, 2, 3, 9): "
  66.  
  67. select = gets.chomp
  68. case
  69. when '1' == select
  70. # データの入力
  71. input_data
  72. when '2' == select
  73. # データの出力
  74. output_data
  75. when '3' == select
  76. # 今日の日付の表示
  77. print_date
  78. when '9' == select
  79. # 終了
  80. break
  81. else
  82. # 処理選択画面に戻る
  83. end
  84. end
  85. end
  86. end
  87.  
  88. testapp = TestAppInfoManager.new
  89.  
  90. testapp.select_menu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement