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

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

Към профила на Кристиян Тодоров

Резултати

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

Код

class LazyMode
def self.create_file(set_name, &block)
file = File.new(set_name, &block)
file
end
end
class LazyMode::Date
attr_accessor :day, :month, :year
def initialize(date)
parsed_date = date.split '-'
@year = parsed_date[0].to_i
@month = parsed_date[1].to_i
@day = parsed_date[2].to_i
end
def to_s
date = String.new.tap do |date|
date << @year.to_s.rjust(4, "0") << '-'
date << @month.to_s.rjust(2, "0") << '-'
date << @day.to_s.rjust(2, "0")
end
end
end
class LazyMode::File
attr_reader :notes, :name
def initialize(name, &block)
@name = name
@notes = []
instance_eval &block
end
def note(header, *tags, &block)
current_note = LazyMode::Note.new(header, name, *tags, &block)
current_note.instance_eval &block
@notes << current_note
end
end
class LazyMode::Note
attr_reader :header, :file_name, :body, :status, :tags
def initialize(header, file_name, *tags, &block)
@file_name = file_name
@header = header
@tags = tags
@status = :topostpone
end
def scheduled(date)
@scheduled = LazyMode::Date.new(date)
puts @scheduled
end
def status(set_status)
@status = set_status
end
def body(set_body)
@body = set_body
end
end

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

.....F..FFFF2012-12-12
2012-12-13
F2012-12-11
2012-12-13
F2012-12-05
2012-12-13
F2012-11-12
2012-12-13
F2012-11-12
F2012-08-07
F2012-12-12
2012-12-13
F2012-12-11
2012-12-15
F2012-12-05
2012-12-13
F2012-11-12
2012-12-13
F2012-11-12
F2012-08-07
F2012-12-12
2012-12-12
2012-12-12
F2012-12-12
2012-12-12
2012-12-12
F2012-12-12
2012-12-12
2012-12-12
F2012-12-12
2012-12-12
2012-12-12
F2012-12-12
2012-12-12
2012-12-12
F..

Failures:

  1) LazyMode LazyMode::Note can have nested notes
     Failure/Error: note 'one' do
     NoMethodError:
       undefined method `note' for #<LazyMode::Note:0x007f0b8f8fdaa8>
     # /tmp/d20160107-5693-qt62in/spec.rb:101:in `block (5 levels) in <top (required)>'
     # /tmp/d20160107-5693-qt62in/solution.rb:37:in `instance_eval'
     # /tmp/d20160107-5693-qt62in/solution.rb:37:in `note'
     # /tmp/d20160107-5693-qt62in/spec.rb:100:in `block (4 levels) in <top (required)>'
     # /tmp/d20160107-5693-qt62in/solution.rb:32:in `instance_eval'
     # /tmp/d20160107-5693-qt62in/solution.rb:32:in `initialize'
     # /tmp/d20160107-5693-qt62in/solution.rb:3:in `new'
     # /tmp/d20160107-5693-qt62in/solution.rb:3:in `create_file'
     # /tmp/d20160107-5693-qt62in/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 LazyMode::Note #status has status
     Failure/Error: expect(file.notes.first.status).to eq(:postponed)
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160107-5693-qt62in/solution.rb:57:in `status'
     # /tmp/d20160107-5693-qt62in/spec.rb:65:in `block (4 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 LazyMode::Note #status can have default status
     Failure/Error: expect(file.notes.first.status).to eq(:topostpone)
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160107-5693-qt62in/solution.rb:57:in `status'
     # /tmp/d20160107-5693-qt62in/spec.rb:74:in `block (4 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 LazyMode::Note #body has body
     Failure/Error: expect(file.notes.first.body).to eq('Do not forget to...')
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160107-5693-qt62in/solution.rb:61:in `body'
     # /tmp/d20160107-5693-qt62in/spec.rb:85:in `block (4 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 LazyMode::Note #body can have no body
     Failure/Error: expect(file.notes.first.body).to eq('')
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160107-5693-qt62in/solution.rb:61:in `body'
     # /tmp/d20160107-5693-qt62in/spec.rb:94:in `block (4 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 without repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007f0b8f587838>
     # /tmp/d20160107-5693-qt62in/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)>'

  7) 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:0x007f0b8f580a38>
     # /tmp/d20160107-5693-qt62in/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)>'

  8) 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:0x007f0b8f56dc30>
     # /tmp/d20160107-5693-qt62in/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)>'

  9) 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:0x007f0b8f548c78>
     # /tmp/d20160107-5693-qt62in/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)>'

  10) 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:0x007f0b8f535b28>
     # /tmp/d20160107-5693-qt62in/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)>'

  11) LazyMode#daily_agenda returns nested notes
     Failure/Error: note 'subtask' do
     NoMethodError:
       undefined method `note' for #<LazyMode::Note:0x007f0b8f52c4d8>
     # /tmp/d20160107-5693-qt62in/spec.rb:224:in `block (5 levels) in <top (required)>'
     # /tmp/d20160107-5693-qt62in/solution.rb:37:in `instance_eval'
     # /tmp/d20160107-5693-qt62in/solution.rb:37:in `note'
     # /tmp/d20160107-5693-qt62in/spec.rb:221:in `block (4 levels) in <top (required)>'
     # /tmp/d20160107-5693-qt62in/solution.rb:32:in `instance_eval'
     # /tmp/d20160107-5693-qt62in/solution.rb:32:in `initialize'
     # /tmp/d20160107-5693-qt62in/solution.rb:3:in `new'
     # /tmp/d20160107-5693-qt62in/solution.rb:3:in `create_file'
     # /tmp/d20160107-5693-qt62in/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)>'

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

  13) 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:0x007f0b8f4f3c00>
     # /tmp/d20160107-5693-qt62in/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)>'

  14) 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:0x007f0b8f4c5238>
     # /tmp/d20160107-5693-qt62in/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)>'

  15) 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:0x007f0b8f4b2b60>
     # /tmp/d20160107-5693-qt62in/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)>'

  16) 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:0x007f0b8f4a7350>
     # /tmp/d20160107-5693-qt62in/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)>'

  17) LazyMode#weekly_agenda returns nested notes
     Failure/Error: note 'subtask' do
     NoMethodError:
       undefined method `note' for #<LazyMode::Note:0x007f0b8f49a628>
     # /tmp/d20160107-5693-qt62in/spec.rb:353:in `block (5 levels) in <top (required)>'
     # /tmp/d20160107-5693-qt62in/solution.rb:37:in `instance_eval'
     # /tmp/d20160107-5693-qt62in/solution.rb:37:in `note'
     # /tmp/d20160107-5693-qt62in/spec.rb:350:in `block (4 levels) in <top (required)>'
     # /tmp/d20160107-5693-qt62in/solution.rb:32:in `instance_eval'
     # /tmp/d20160107-5693-qt62in/solution.rb:32:in `initialize'
     # /tmp/d20160107-5693-qt62in/solution.rb:3:in `new'
     # /tmp/d20160107-5693-qt62in/solution.rb:3:in `create_file'
     # /tmp/d20160107-5693-qt62in/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)>'

  18) 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:0x007f0b8f490038>
     # /tmp/d20160107-5693-qt62in/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 body text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for #<LazyMode::File:0x007f0b8f47b890>
     # /tmp/d20160107-5693-qt62in/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)>'

  20) 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:0x007f0b8f3f1bb8>
     # /tmp/d20160107-5693-qt62in/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)>'

  21) 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:0x007f0b8f3e2848>
     # /tmp/d20160107-5693-qt62in/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)>'

  22) 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:0x007f0b8f3dbb38>
     # /tmp/d20160107-5693-qt62in/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.02322 seconds
31 examples, 22 failures

Failed examples:

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

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

Кристиян обнови решението на 21.12.2015 16:56 (преди около 9 години)

+class LazyMode
+ def self.create_file(set_name, &block)
+ file = File.new(set_name, &block)
+ file
+ end
+end
+
+class LazyMode::Date
+ attr_accessor :day, :month, :year
+
+ def initialize(date)
+ parsed_date = date.split '-'
+ @year = parsed_date[0].to_i
+ @month = parsed_date[1].to_i
+ @day = parsed_date[2].to_i
+ end
+
+ def to_s
+ date = String.new.tap do |date|
+ date << @year.to_s.rjust(4, "0") << '-'
+ date << @month.to_s.rjust(2, "0") << '-'
+ date << @day.to_s.rjust(2, "0")
+ end
+ end
+end
+
+class LazyMode::File
+ attr_reader :notes, :name
+ def initialize(name, &block)
+ @name = name
+ @notes = []
+ instance_eval &block
+ end
+
+ def note(header, *tags, &block)
+ current_note = LazyMode::Note.new(header, name, *tags, &block)
+ current_note.instance_eval &block
+ @notes << current_note
+ end
+end
+
+class LazyMode::Note
+ attr_reader :header, :file_name, :body, :status, :tags
+
+ def initialize(header, file_name, *tags, &block)
+ @file_name = file_name
+ @header = header
+ @tags = tags
+ @status = :topostpone
+ end
+
+ def scheduled(date)
+ @scheduled = LazyMode::Date.new(date)
+ puts @scheduled
+ end
+
+ def status(set_status)
+ @status = set_status
+ end
+
+ def body(set_body)
+ @body = set_body
+ end
+end