Решение на Седма задача от Росен Тодоров

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

Към профила на Росен Тодоров

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 14 успешни тест(а)
  • 17 неуспешни тест(а)

Код

class LazyMode
class Date
attr_accessor :date
def initialize(date)
@date = date
end
def year
@date[0..3].to_i
end
def month
@date[5..6].to_i
end
def day
@date[8..9].to_i
end
def to_s
@date
end
end
def self.create_file(name, &block)
File.new(name, &block)
end
class File
attr_accessor :name, :notes
def initialize(name, &block)
@name = name
@notes = Array.new
instance_eval &block
end
def note(header, *tags, &block)
notes << Note.new(@name, header, *tags, &block)
block.call &block
end
def status(symbol)
notes.last.status = symbol
end
def body(string)
notes.last.body = string
end
def scheduled(date)
notes.last.date = Date.new(date)
end
def daily_agenda(date)
notes.select { |note| note.date.to_s == date.to_s }
end
end
class Note
attr_accessor :header, :file_name, :body, :status, :tags, :date
def initialize(file_name, header, *tags, &block)
@header = header
@tags = tags
@file_name = file_name
@body = String.new
@status = :topostpone
end
end
end

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

............FFFFFFFFFFFFFFFFF..

Failures:

  1) LazyMode#daily_agenda returns note scheduled without repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for #<Array:0x007fc048f88148>
     # /tmp/d20160107-5693-12rm447/spec.rb:131: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#daily_agenda returns note scheduled with daily repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for []:Array
     # /tmp/d20160107-5693-12rm447/spec.rb:153: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 with weekly repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for []:Array
     # /tmp/d20160107-5693-12rm447/spec.rb:175: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 monthly repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for []:Array
     # /tmp/d20160107-5693-12rm447/spec.rb:198: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 does not return note whose start date is in the future
     Failure/Error: expect(agenda.notes.size).to eq(0)
     NoMethodError:
       undefined method `notes' for []:Array
     # /tmp/d20160107-5693-12rm447/spec.rb:216: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 nested notes
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for #<Array:0x007fc048d68110>
     # /tmp/d20160107-5693-12rm447/spec.rb:232: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#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:0x007fc048d5dff8>
     # /tmp/d20160107-5693-12rm447/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)>'

  8) 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:0x007fc048d54ed0>
     # /tmp/d20160107-5693-12rm447/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)>'

  9) 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:0x007fc048d4f200>
     # /tmp/d20160107-5693-12rm447/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)>'

  10) 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:0x007fc048d4aef8>
     # /tmp/d20160107-5693-12rm447/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)>'

  11) 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:0x007fc048d3ed38>
     # /tmp/d20160107-5693-12rm447/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)>'

  12) 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:0x007fc049b81dc8>
     # /tmp/d20160107-5693-12rm447/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)>'

  13) LazyMode#where filters by tag
     Failure/Error: notes = @agenda.where(tag: :important).notes
     NoMethodError:
       undefined method `where' for #<Array:0x007fc049b76928>
     # /tmp/d20160107-5693-12rm447/spec.rb:391: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#where filters by body text
     Failure/Error: notes = @agenda.where(text: /Very/).notes
     NoMethodError:
       undefined method `where' for #<Array:0x007fc049c03fa8>
     # /tmp/d20160107-5693-12rm447/spec.rb:409: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 header text
     Failure/Error: notes = @agenda.where(text: /not important/).notes
     NoMethodError:
       undefined method `where' for #<Array:0x007fc049c00060>
     # /tmp/d20160107-5693-12rm447/spec.rb:421: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 status
     Failure/Error: notes = @agenda.where(status: :postponed).notes
     NoMethodError:
       undefined method `where' for #<Array:0x007fc049c15780>
     # /tmp/d20160107-5693-12rm447/spec.rb:433: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 multiple filters
     Failure/Error: notes = @agenda.where(text: /important/, status: :postponed).notes
     NoMethodError:
       undefined method `where' for #<Array:0x007fc049c0f4e8>
     # /tmp/d20160107-5693-12rm447/spec.rb:444: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.01653 seconds
31 examples, 17 failures

Failed examples:

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

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

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

+class LazyMode
+ class Date
+ attr_accessor :date
+
+ def initialize(date)
+ @date = date
+ end
+
+ def year
+ @date[0..3].to_i
+ end
+
+ def month
+ @date[5..6].to_i
+ end
+
+ def day
+ @date[8..9].to_i
+ end
+
+ def to_s
+ @date
+ end
+ end
+
+ def self.create_file(name, &block)
+ File.new(name, &block)
+ end
+
+ class File
+ attr_accessor :name, :notes
+
+ def initialize(name, &block)
+ @name = name
+ @notes = Array.new
+ instance_eval &block
+ end
+
+ def note(header, *tags, &block)
+ notes << Note.new(@name, header, *tags, &block)
+ block.call &block
+ end
+
+ def status(symbol)
+ notes.last.status = symbol
+ end
+
+ def body(string)
+ notes.last.body = string
+ end
+
+ def scheduled(date)
+ notes.last.date = Date.new(date)
+ end
+
+ def daily_agenda(date)
+ notes.select { |note| note.date.to_s == date.to_s }
+ end
+ end
+
+ class Note
+ attr_accessor :header, :file_name, :body, :status, :tags, :date
+
+ def initialize(file_name, header, *tags, &block)
+ @header = header
+ @tags = tags
+ @file_name = file_name
+ @body = String.new
+ @status = :topostpone
+ end
+ end
+end