Guest User

Untitled

a guest
Feb 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. # coding:utf-8
  2. require 'date'
  3.  
  4. class AnkiData
  5. include Enumerable
  6.  
  7. def initialize( &block )
  8. @anki_set_maker = block
  9. @data = Array.new
  10. end
  11.  
  12. # i に応じたセットを追加
  13. def <<( i )
  14. @data << @anki_set_maker.call( i )
  15. end
  16.  
  17. def []( i )
  18. @data[ i % @data.size ]
  19. end
  20.  
  21. def last?( comp_data )
  22. @data[-1] == comp_data
  23. end
  24.  
  25. def each
  26. @data.each {|d| yield d }
  27. end
  28. end
  29.  
  30. class DWM
  31. def initialize
  32. @day = 1
  33. @week = 7
  34. @month = 30
  35. end
  36.  
  37. attr_accessor :day, :week, :month
  38.  
  39. def make_schedule( start_day, data )
  40. schedule = []
  41. d_pos = 0
  42.  
  43. # :month の暗記予定が、暗記データの最後の要素と同じになるまでスケジュールを組む
  44. # :month が最後の要素となるまで、:date, :day, :week は繰り返す
  45. while ( d_pos == 0 ) || !( data.last?( schedule[-1][:month] ) )
  46. pos_day = start_day + d_pos
  47. day_schedule = Hash.new
  48.  
  49. day_schedule[:date] = pos_day
  50. day_schedule[:data] = data[ d_pos ]
  51.  
  52. if d_pos != 0
  53. day_schedule[:day] = schedule[-1*@day][:data]
  54. if d_pos > @week
  55. day_schedule[:week] = schedule[-1*@week][:data]
  56. if d_pos > @month
  57. day_schedule[:month] = schedule[-1*@month][:data]
  58. end
  59. end
  60. end
  61.  
  62. schedule << day_schedule
  63. d_pos += 1
  64. end
  65.  
  66. return schedule
  67. end
  68. end
  69.  
  70.  
  71. if __FILE__ == $0
  72. # Dialogue 1800 の暗記スケジュールを作る
  73. # 1日に2個のセクションを新しく覚える
  74. # 開始日はスクリプト実行日から
  75.  
  76. anki_data = AnkiData.new {|i| [(2*i-1), 2*i] }
  77.  
  78. (1..55).each do |i|
  79. anki_data << i
  80. end
  81.  
  82. schedule = DWM.new.make_schedule( Date.today, anki_data )
  83.  
  84. now_month = nil
  85. schedule.each do |s|
  86. unless s[:date].month == now_month
  87. puts '--------------------------------'
  88. puts "\t*** #{Date::MONTHNAMES[s[:date].month]} ***"
  89. puts '--------------------------------'
  90. now_month = s[:date].month
  91. end
  92.  
  93. today_schedule = "[ ] #{s[:data].join(',')}"
  94.  
  95. [:day, :week, :month].each do |r|
  96. today_schedule += "\t#{s[ r ].join(',')}" if s[ r ]
  97. end
  98.  
  99. puts "#{s[:date].day}日\t: " + today_schedule
  100. end
  101. end
Add Comment
Please, Sign In to add comment