Решение на Седма задача от Георги Стефанов

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

Към профила на Георги Стефанов

Резултати

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

Код

class LazyMode
class Note
attr_reader :header, :tags, :file_name
attr_reader :body, :status, :scheduled, :small_notes
def initialize(head, *tags, name)
@header = head
@tags = *tags
@small_notes = []
@file_name = name
@status = :topostpone
end
def date
@scheduled
end
def status(status = 0)
if status == 0
@status
else
@status = :postponed
end
end
def body(body = 0)
if body == 0
@body
else
@body = body
end
end
def scheduled(schedule)
@scheduled = schedule
end
def file_name
@file_name
end
def small_note(small_note = 0)
if small_note == 0
@small_notes
else
@small_notes << small_note
end
end
def note(head, *tags, &block)
name = self.instance_variable_get(:@name)
note = Note.new(head, *tags, name)
note.instance_eval(&block) if block_given?
small_note(note)
end
end
class Date < Note
def initialize(string)
@date = string
@period = string.split(' ')[1]
date = string.split(' ')[0].split('-')
@year, @month, @day = date[0], date[1], date[2]
end
def date
@date
end
def year
@year.to_i
end
def month
@month.to_i
end
def day
@day.to_i
end
def to_s
@year.insert(0, '0') if @year.length < 4
@month.insert(0, '0') if @month.length < 2
@day.insert(0, '0') if @day.length < 2
@year + '-' + @month + '-' + @day
end
end
class File < Date
attr_reader :scheduled
def initialize(name)
@name = name
@notes = []
end
def note(head, *tags, &block)
note = Note.new(head, *tags, self.instance_variable_get(:@name))
note.instance_eval(&block) if block_given?
add_note(note)
end
def scheduled(date)
@scheduled = date
end
def date
@scheduled
end
def notes
@notes
end
def add_note(note)
@notes << note
end
end
def LazyMode.create_file(name, &block)
file = File.new(name)
file.instance_eval(&block) if block_given?
file
end
end

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

.....F.....FFFFFFFFFFFFFFFFFFF.

Failures:

  1) LazyMode LazyMode::Note can have nested notes
     Failure/Error: expect(file.notes.first.body).to eq('')
       
       expected: ""
            got: nil
       
       (compared using ==)
     # /tmp/d20160107-5693-1djn9u2/spec.rb:114: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 #body can have no body
     Failure/Error: expect(file.notes.first.body).to eq('')
       
       expected: ""
            got: nil
       
       (compared using ==)
     # /tmp/d20160107-5693-1djn9u2/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)>'

  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:0x007fe328fd1458>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328fa8a30>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328dcc428>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328dc25b8>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328db8a18>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328db1498>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328da7150>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328d9fc48>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe328d94de8>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329bd90c0>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329bced78>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329bcccf8>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329c599c8>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329c6d5e0>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329c6ae08>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329c62c08>
     # /tmp/d20160107-5693-1djn9u2/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:0x007fe329c602f0>
     # /tmp/d20160107-5693-1djn9u2/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.create_file can assign name to files
     Failure/Error: expect(file.name).to eq('important_notes_and_todos')
     NoMethodError:
       undefined method `name' for #<LazyMode::File:0x007fe329c505d0>
     # /tmp/d20160107-5693-1djn9u2/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.01683 seconds
31 examples, 20 failures

Failed examples:

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

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

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

+class LazyMode
+
+ class Note
+
+ attr_reader :header, :tags, :file_name
+ attr_reader :body, :status, :scheduled, :small_notes
+
+ def initialize(head, *tags, name)
+ @header = head
+ @tags = *tags
+ @small_notes = []
+ @file_name = name
+ @status = :topostpone
+ end
+
+ def date
+ @scheduled
+ end
+
+ def status(status = 0)
+ if status == 0
+ @status
+ else
+ @status = :postponed
+ end
+ end
+
+ def body(body = 0)
+ if body == 0
+ @body
+ else
+ @body = body
+ end
+ end
+
+ def scheduled(schedule)
+ @scheduled = schedule
+ end
+
+ def file_name
+ @file_name
+ end
+
+ def small_note(small_note = 0)
+ if small_note == 0
+ @small_notes
+ else
+ @small_notes << small_note
+ end
+ end
+
+ def note(head, *tags, &block)
+ name = self.instance_variable_get(:@name)
+ note = Note.new(head, *tags, name)
+ note.instance_eval(&block) if block_given?
+ small_note(note)
+ end
+ end
+
+ class Date < Note
+ def initialize(string)
+ @date = string
+ @period = string.split(' ')[1]
+ date = string.split(' ')[0].split('-')
+ @year, @month, @day = date[0], date[1], date[2]
+ end
+
+ def date
+ @date
+ end
+
+ def year
+ @year.to_i
+ end
+
+ def month
+ @month.to_i
+ end
+
+ def day
+ @day.to_i
+ end
+
+ def to_s
+ @year.insert(0, '0') if @year.length < 4
+ @month.insert(0, '0') if @month.length < 2
+ @day.insert(0, '0') if @day.length < 2
+ @year + '-' + @month + '-' + @day
+ end
+ end
+
+ class File < Date
+
+ attr_reader :scheduled
+
+ def initialize(name)
+ @name = name
+ @notes = []
+ end
+
+ def note(head, *tags, &block)
+ note = Note.new(head, *tags, self.instance_variable_get(:@name))
+ note.instance_eval(&block) if block_given?
+ add_note(note)
+ end
+
+ def scheduled(date)
+ @scheduled = date
+ end
+
+ def date
+ @scheduled
+ end
+
+ def notes
+ @notes
+ end
+
+ def add_note(note)
+ @notes << note
+ end
+ end
+
+ def LazyMode.create_file(name, &block)
+ file = File.new(name)
+ file.instance_eval(&block) if block_given?
+ file
+ end
+end