Решение на Седма задача от Слави Боянов

Обратно към всички решения

Към профила на Слави Боянов

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 12 успешни тест(а)
  • 19 неуспешни тест(а)

Код

module LazyMode
class Date
def initialize(date)
@year = date.split("-")[0]
@month = date.split("-")[1]
@day = date.split("-")[2]
end
def to_s
"#{@year}-#{@month}-#{@month}"
end
def year
@year.to_i
end
def month
@year.to_i
end
def day
@year.to_i
end
end
def self.create_file (name, &block)
file = File.new(name)
file.instance_eval(&block)
file
end
private
class File
attr_reader :name, :notes
def initialize(name)
@name = name
@notes = []
end
def note(name, *tags, &block)
new = Note.new(name, tags, @name)
new.instance_eval(&block)
@notes.push(new)
end
end
class Note
attr_reader :notes, :header, :tags, :file_name, :file_name, :date
def initialize(header, *tags, file_name)
@header = header
@notes = []
@tags = tags[0]
@status = :topostpone
@body = ""
@file_name = file_name
end
def note(name, *tags, &block)
new = Note.new(name, tags, @file_name)
new.instance_eval(&block)
@notes.push(new)
end
def status(new_status = @status)
@status = new_status
end
def body(new_body = @body)
@body = new_body
end
def scheduled(schedule)
@date = Date.new(schedule.split(" ")[0])
end
end
end

Лог от изпълнението

.FF.........FFFFFFFFFFFFFFFFF..

Failures:

  1) LazyMode LazyMode::Date can parse month
     Failure/Error: expect(date.month).to eq(10)
       
       expected: 10
            got: 2012
       
       (compared using ==)
     # /tmp/d20160107-5693-y8pu6n/spec.rb:10:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) LazyMode LazyMode::Date can parse day
     Failure/Error: expect(date.day).to eq(3)
       
       expected: 3
            got: 2012
       
       (compared using ==)
     # /tmp/d20160107-5693-y8pu6n/spec.rb:15:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) LazyMode#daily_agenda returns note scheduled without repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0d6bf3d0>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:130:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) LazyMode#daily_agenda returns note scheduled with daily repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0d699a90>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:152:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) LazyMode#daily_agenda returns note scheduled with weekly repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0d4bd280>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:174:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) LazyMode#daily_agenda returns note scheduled with monthly repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2013-01-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0d4b1890>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:197:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) LazyMode#daily_agenda does not return note whose start date is in the future
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-10-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0d4a2548>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:215:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) LazyMode#daily_agenda returns nested notes
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-08-06'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0d4979e0>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:230:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) LazyMode#weekly_agenda returns note scheduled without repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-12-06'))
     NoMethodError:
       undefined method `weekly_agenda' for #<LazyMode::File:0x007fbb0d48ee08>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:248:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-12-06'))
     NoMethodError:
       undefined method `weekly_agenda' for #<LazyMode::File:0x007fbb0e2c7a60>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:270:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) LazyMode#weekly_agenda returns note scheduled with weekly repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-12-10'))
     NoMethodError:
       undefined method `weekly_agenda' for #<LazyMode::File:0x007fbb0e2bb968>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:294:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) LazyMode#weekly_agenda returns note scheduled with monthly repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2013-01-10'))
     NoMethodError:
       undefined method `weekly_agenda' for #<LazyMode::File:0x007fbb0e2b8e20>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:326:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) LazyMode#weekly_agenda does not return note whose start date is in the future
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-10-12'))
     NoMethodError:
       undefined method `weekly_agenda' for #<LazyMode::File:0x007fbb0e345050>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:344:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) LazyMode#weekly_agenda returns nested notes
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-09-05'))
     NoMethodError:
       undefined method `weekly_agenda' for #<LazyMode::File:0x007fbb0e35dfd8>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:359:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) LazyMode#where filters by tag
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0e356c60>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:387:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) LazyMode#where filters by body text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0e34d930>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:387:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) LazyMode#where filters by header text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0e33e520>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:387:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) LazyMode#where filters by status
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0e339890>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:387:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) LazyMode#where filters by multiple filters
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007fbb0e331b18>
     # /tmp/d20160107-5693-y8pu6n/spec.rb:387:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01683 seconds
31 examples, 19 failures

Failed examples:

rspec /tmp/d20160107-5693-y8pu6n/spec.rb:8 # LazyMode LazyMode::Date can parse month
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:13 # LazyMode LazyMode::Date can parse day
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:119 # LazyMode#daily_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:141 # LazyMode#daily_agenda returns note scheduled with daily repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:163 # LazyMode#daily_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:186 # LazyMode#daily_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:208 # LazyMode#daily_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:219 # LazyMode#daily_agenda returns nested notes
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:237 # LazyMode#weekly_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:259 # LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:283 # LazyMode#weekly_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:315 # LazyMode#weekly_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:337 # LazyMode#weekly_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:348 # LazyMode#weekly_agenda returns nested notes
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:390 # LazyMode#where filters by tag
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:408 # LazyMode#where filters by body text
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:420 # LazyMode#where filters by header text
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:432 # LazyMode#where filters by status
rspec /tmp/d20160107-5693-y8pu6n/spec.rb:443 # LazyMode#where filters by multiple filters

История (1 версия и 0 коментара)

Слави обнови решението на 21.12.2015 17:25 (преди около 9 години)

+module LazyMode
+ class Date
+ def initialize(date)
+ @year = date.split("-")[0]
+ @month = date.split("-")[1]
+ @day = date.split("-")[2]
+ end
+
+ def to_s
+ "#{@year}-#{@month}-#{@month}"
+ end
+
+ def year
+ @year.to_i
+ end
+
+ def month
+ @year.to_i
+ end
+
+ def day
+ @year.to_i
+ end
+ end
+
+ def self.create_file (name, &block)
+ file = File.new(name)
+ file.instance_eval(&block)
+ file
+ end
+
+ private
+
+ class File
+ attr_reader :name, :notes
+
+ def initialize(name)
+ @name = name
+ @notes = []
+ end
+
+ def note(name, *tags, &block)
+ new = Note.new(name, tags, @name)
+ new.instance_eval(&block)
+ @notes.push(new)
+ end
+ end
+
+ class Note
+ attr_reader :notes, :header, :tags, :file_name, :file_name, :date
+
+ def initialize(header, *tags, file_name)
+ @header = header
+ @notes = []
+ @tags = tags[0]
+ @status = :topostpone
+ @body = ""
+ @file_name = file_name
+ end
+
+ def note(name, *tags, &block)
+ new = Note.new(name, tags, @file_name)
+ new.instance_eval(&block)
+ @notes.push(new)
+ end
+
+ def status(new_status = @status)
+ @status = new_status
+ end
+
+ def body(new_body = @body)
+ @body = new_body
+ end
+
+ def scheduled(schedule)
+ @date = Date.new(schedule.split(" ")[0])
+ end
+ end
+end