Решение на Седма задача от Петър Иванов

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

Към профила на Петър Иванов

Резултати

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

Код

module LazyMode
def self.create_file(file_name, &block)
file = LazyMode::File.new(file_name)
file.instance_eval(&block)
end
end
class LazyMode::Date
attr_reader :year, :month, :day
def initialize(string)
@representation = string
@year = string.split('-')[0].to_i
@month = string.split('-')[1].to_i
@day = string.split('-')[2].to_i
end
def to_s
@representation
end
end
module LazyMode::NoteOperations
def status(string)
@status = string
end
def body(string)
@body = string
end
def scheduled(string)
@scheduled = string
end
end
class LazyMode::Note
attr_reader :header, :file_name, :tags
attr_writer :header, :file_name, :tags
def initialize(header, *tags, file_name, file)
@header, @file_name = header, file_name
@tags = tags
@status = :topostpone
@body, @scheduled = "", ""
@notes = []
@file = file
end
def note(header, *tags, &block)
note = LazyMode::Note(header, *tags)
@notes << note
note.instance_eval(&block)
end
def scheduled(string)
@scheduled = string
end
def status(string = nil)
if string.nil?
@status
else
@status = string
end
end
def body(string = nil)
if string.nil?
@body
else
@body = string
end
end
def to_s
"#{@header} - #{@tags} - #{file_name} #{@body}, #{@status}, #{@scheduled}"
end
end
class LazyMode::File
attr_reader :name, :notes
def initialize(file_name)
@name = file_name
@notes = []
end
def note(header, *tags, &block)
note = LazyMode::Note.new(header, *tags, @name, self)
@notes << note
note.instance_eval(&block)
self
end
def daily_agenda(date)
LazyMode::DailyAgenda.new(date, @notes)
end
def weekly_agenda(date)
end
end
class LazyMode::DailyAgenda
def initialize(date, notes)
@date = date
@notes = notes
end
def notes
end
def where(tag: nil, text: nil, status: nil)
end
end
class LazyMode::WeeklyAgenda
def initialize(date, notes)
@date = date
@notes = notes
end
def notes
end
def where(tag: nil, text: nil, status: nil)
end
end

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

.....F......FFFFFFFFFFFFFFFFFF.

Failures:

  1) LazyMode LazyMode::Note can have nested notes
     Failure/Error: note 'one' do
     NoMethodError:
       undefined method `Note' for LazyMode:Module
     # /tmp/d20160107-5693-12g8k0c/solution.rb:51:in `note'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:101:in `block (5 levels) in <top (required)>'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:92:in `instance_eval'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:92:in `note'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:100:in `block (4 levels) in <top (required)>'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:4:in `instance_eval'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:4:in `create_file'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:99: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 without repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `size' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  3) LazyMode#daily_agenda returns note scheduled with daily repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `size' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  4) LazyMode#daily_agenda returns note scheduled with weekly repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `size' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  5) LazyMode#daily_agenda returns note scheduled with monthly repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `size' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  6) 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 `size' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  7) LazyMode#daily_agenda returns nested notes
     Failure/Error: note 'subtask' do
     NoMethodError:
       undefined method `Note' for LazyMode:Module
     # /tmp/d20160107-5693-12g8k0c/solution.rb:51:in `note'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:224:in `block (5 levels) in <top (required)>'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:92:in `instance_eval'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:92:in `note'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:221:in `block (4 levels) in <top (required)>'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:4:in `instance_eval'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:4:in `create_file'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:220: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 note scheduled without repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/spec.rb:249: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 multiple notes with different dates when scheduled with daily repeater
     Failure/Error: expect(agenda.notes.size).to eq(2)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/spec.rb:271: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 weekly repeater
     Failure/Error: expect(agenda.notes.size).to eq(2)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/spec.rb:295: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 monthly repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/spec.rb:327: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 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 nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/spec.rb:345: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 returns nested notes
     Failure/Error: note 'subtask' do
     NoMethodError:
       undefined method `Note' for LazyMode:Module
     # /tmp/d20160107-5693-12g8k0c/solution.rb:51:in `note'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:353:in `block (5 levels) in <top (required)>'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:92:in `instance_eval'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:92:in `note'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:350:in `block (4 levels) in <top (required)>'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:4:in `instance_eval'
     # /tmp/d20160107-5693-12g8k0c/solution.rb:4:in `create_file'
     # /tmp/d20160107-5693-12g8k0c/spec.rb:349: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 tag
     Failure/Error: notes = @agenda.where(tag: :important).notes
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  15) LazyMode#where filters by body text
     Failure/Error: notes = @agenda.where(text: /Very/).notes
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  16) LazyMode#where filters by header text
     Failure/Error: notes = @agenda.where(text: /not important/).notes
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  17) LazyMode#where filters by status
     Failure/Error: notes = @agenda.where(status: :postponed).notes
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  18) LazyMode#where filters by multiple filters
     Failure/Error: notes = @agenda.where(text: /important/, status: :postponed).notes
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/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)>'

  19) LazyMode.create_file can assign name to files
     Failure/Error: expect(file.name).to eq('important_notes_and_todos')
     NoMethodError:
       undefined method `name' for nil:NilClass
     # /tmp/d20160107-5693-12g8k0c/spec.rb:460: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.01384 seconds
31 examples, 19 failures

Failed examples:

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

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

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

+module LazyMode
+ def self.create_file(file_name, &block)
+ file = LazyMode::File.new(file_name)
+ file.instance_eval(&block)
+ end
+end
+
+class LazyMode::Date
+ attr_reader :year, :month, :day
+
+ def initialize(string)
+ @representation = string
+ @year = string.split('-')[0].to_i
+ @month = string.split('-')[1].to_i
+ @day = string.split('-')[2].to_i
+ end
+
+ def to_s
+ @representation
+ end
+end
+
+module LazyMode::NoteOperations
+ def status(string)
+ @status = string
+ end
+
+ def body(string)
+ @body = string
+ end
+
+ def scheduled(string)
+ @scheduled = string
+ end
+end
+
+class LazyMode::Note
+ attr_reader :header, :file_name, :tags
+ attr_writer :header, :file_name, :tags
+
+ def initialize(header, *tags, file_name, file)
+ @header, @file_name = header, file_name
+ @tags = tags
+ @status = :topostpone
+ @body, @scheduled = "", ""
+ @notes = []
+ @file = file
+ end
+
+ def note(header, *tags, &block)
+ note = LazyMode::Note(header, *tags)
+ @notes << note
+ note.instance_eval(&block)
+ end
+
+ def scheduled(string)
+ @scheduled = string
+ end
+
+ def status(string = nil)
+ if string.nil?
+ @status
+ else
+ @status = string
+ end
+ end
+
+ def body(string = nil)
+ if string.nil?
+ @body
+ else
+ @body = string
+ end
+ end
+
+ def to_s
+ "#{@header} - #{@tags} - #{file_name} #{@body}, #{@status}, #{@scheduled}"
+ end
+end
+
+class LazyMode::File
+ attr_reader :name, :notes
+
+ def initialize(file_name)
+ @name = file_name
+ @notes = []
+ end
+
+ def note(header, *tags, &block)
+ note = LazyMode::Note.new(header, *tags, @name, self)
+ @notes << note
+ note.instance_eval(&block)
+
+ self
+ end
+
+ def daily_agenda(date)
+ LazyMode::DailyAgenda.new(date, @notes)
+ end
+
+ def weekly_agenda(date)
+ end
+end
+
+class LazyMode::DailyAgenda
+ def initialize(date, notes)
+ @date = date
+ @notes = notes
+ end
+
+ def notes
+ end
+
+ def where(tag: nil, text: nil, status: nil)
+ end
+end
+
+class LazyMode::WeeklyAgenda
+ def initialize(date, notes)
+ @date = date
+ @notes = notes
+ end
+
+ def notes
+ end
+
+ def where(tag: nil, text: nil, status: nil)
+ end
+end