lib/sculd/manager.rb in sculd-0.0.0 vs lib/sculd/manager.rb in sculd-0.0.1

- old
+ new

@@ -10,30 +10,32 @@ # class Sculd::Manager #WEEKDAYS = [ "日", "月", "火", "水", "木", "金", "土" ] WEEKDAYS = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ] + class LoadError < Exception; end + # - def initialize(file) + def initialize(file, io = $stdout) @source_file = file - load_file(@source_file) + load_file(@source_file, io) end def show(num_event, num_task) show_events(num_event) show_tasks(num_task) end private # read, parse file and set data to @events and @tasks. - def load_file(file) + def load_file(file, io = $stdio) @plans = [] File.open(file, "r").readlines.each_with_index do |line, index| begin - date, type, option = Sculd::Plan.parse(line) + date, type, option = Sculd::Plan.parse(line, io) option = option.to_i next unless type case type when "@" plan_type = Sculd::Plan::Schedule @@ -47,11 +49,14 @@ option = 7 if option == 0 else next end @plans << plan_type.new(date, option, line) + rescue Sculd::Plan::WeekdayMismatchError + io.puts "error occured at #{index}: #{line}" + raise LoadError rescue - #puts "error occured at #{index}: #{line}" + # do nothing end end end # Show events in 'num' days from todary.