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

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

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

Резултати

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

Код

class LazyMode
def initialize
@new_file
end
class Date
def initialize(string)
@date = string.split('-')
end
def year
@date[0].to_i
end
def month
@date[1].to_i
end
def day
@date[2].to_i
end
def to_s
("0" * (4 - year.to_s.length)) << "#{year}-" <<
("0" * (2 - month.to_s.length)) << "#{month}-" <<
("0" * (2 - day.to_s.length)) << "#{day}"
end
def add_day
if day == 30
@date[2] = 1.to_s
add_month
else
@date[2] = (day + 1).to_s
end
end
def add_month
if month == 12
@date[1] = 1.to_s
add_year
else
@date[1] = (month + 1).to_s
end
end
def add_year
@date[0] = (year + 1).to_s
end
end
def self.create_file(name, &block)
@new_file = File.new(name, &block)
@new_file
end
module More
def body(string = nil)
string != nil ? @content = string : @content
end
def status(status = nil)
status != nil ? @status = status : @status
end
def scheduled(date = nil)
if date != nil && date.size > 10
@date = Date.new(date[0...date.index('+') - 1])
elsif date != nil
@date = date
else
@date
end
end
def date
scheduled
end
end
class Note
include More
def initialize(*args)
@args = args
@content = ""
@status = :topostpone
@date
@in_notes = []
end
def header
@args[0]
end
def file_name
@args[1]
end
def tags
@args.last
end
def note(title = nil , *args, &var)
if block_given?
current_file = @args[1]
new_note = Note.new(title, current_file, args)
new_note.instance_exec(&var)
@in_notes << new_note
else
@in_notes
end
end
end
class File
def initialize(name, &block)
@name = name
@notes = []
self.instance_eval(&block)
end
def note(title, *args, &var)
current_file = @name
new_note = Note.new(title, current_file, args)
new_note.instance_exec(&var) if block_given?
@notes << new_note
end
def name
@name
end
def notes
@notes
end
def daily_agenda(date)
notes = @notes
DailyAgendaReturnObject.new(date, notes)
end
def weekly_agenda(date)
notes = @notes
WeeklyAgendaReturnObject.new(date, notes)
end
class DailyAgendaReturnObject
def initialize(given_date, notes)
@notes = notes.reject{ |x| x.date.to_s != given_date.to_s }
#inside_notes(given_date, notes)
@notes
end
=begin
def inside_notes(given_date, notes)
notes.each do |new_note|
new_notes = new_note.note.reject{ |x| x.date.to_s !=
given_date.to_s }
@notes.concat(new_notes)
end
end
=end
def notes
@notes
end
def where
end
end
class WeeklyAgendaReturnObject
def initialize(given_date, notes)
@notes = []
# 7.times do
# @notes.concat(notes.reject{ |x| x.date.to_s != given_date.to_s })
# given_date.add_day
# end
#inside_notes(given_date, notes)
@notes
end
=begin
def inside_notes(given_date, notes)
check = given_date
notes.each do |new_note|
7.times do
new_notes = new_note.note.reject{ |x| x.date.to_s !=
check.to_s }
@notes.concat(new_notes)
check.add_day
end
check = given_date
end
end
=end
def notes
@notes
end
def where
end
end
end
end

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

............FFFF.FFFFF.FFFFFF..

Failures:

  1) LazyMode#daily_agenda returns note scheduled without repeater
     Failure/Error: expect(note.date.year).to eq(2012)
     NoMethodError:
       undefined method `year' for "2012-12-12":String
     # /tmp/d20160107-5693-16w75z4/spec.rb:136: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)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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 returns nested notes
     Failure/Error: expect(agenda.notes.size).to eq(1)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)>'

  6) LazyMode#weekly_agenda returns note scheduled without repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)>'

  7) LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
     Failure/Error: expect(agenda.notes.size).to eq(2)
       
       expected: 2
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)>'

  8) LazyMode#weekly_agenda returns note scheduled with weekly repeater
     Failure/Error: expect(agenda.notes.size).to eq(2)
       
       expected: 2
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)>'

  9) LazyMode#weekly_agenda returns note scheduled with monthly repeater
     Failure/Error: expect(agenda.notes.size).to eq(1)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/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)>'

  10) LazyMode#weekly_agenda returns nested notes
     Failure/Error: expect(agenda.notes.size).to eq(1)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-16w75z4/spec.rb:361: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#where filters by tag
     Failure/Error: notes = @agenda.where(tag: :important).notes
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20160107-5693-16w75z4/solution.rb:176:in `where'
     # /tmp/d20160107-5693-16w75z4/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)>'

  12) LazyMode#where filters by body text
     Failure/Error: notes = @agenda.where(text: /Very/).notes
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20160107-5693-16w75z4/solution.rb:176:in `where'
     # /tmp/d20160107-5693-16w75z4/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)>'

  13) LazyMode#where filters by header text
     Failure/Error: notes = @agenda.where(text: /not important/).notes
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20160107-5693-16w75z4/solution.rb:176:in `where'
     # /tmp/d20160107-5693-16w75z4/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)>'

  14) LazyMode#where filters by status
     Failure/Error: notes = @agenda.where(status: :postponed).notes
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20160107-5693-16w75z4/solution.rb:176:in `where'
     # /tmp/d20160107-5693-16w75z4/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)>'

  15) LazyMode#where filters by multiple filters
     Failure/Error: notes = @agenda.where(text: /important/, status: :postponed).notes
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20160107-5693-16w75z4/solution.rb:176:in `where'
     # /tmp/d20160107-5693-16w75z4/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.01765 seconds
31 examples, 15 failures

Failed examples:

rspec /tmp/d20160107-5693-16w75z4/spec.rb:119 # LazyMode#daily_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:141 # LazyMode#daily_agenda returns note scheduled with daily repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:163 # LazyMode#daily_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:186 # LazyMode#daily_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:219 # LazyMode#daily_agenda returns nested notes
rspec /tmp/d20160107-5693-16w75z4/spec.rb:237 # LazyMode#weekly_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:259 # LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:283 # LazyMode#weekly_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:315 # LazyMode#weekly_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-16w75z4/spec.rb:348 # LazyMode#weekly_agenda returns nested notes
rspec /tmp/d20160107-5693-16w75z4/spec.rb:390 # LazyMode#where filters by tag
rspec /tmp/d20160107-5693-16w75z4/spec.rb:408 # LazyMode#where filters by body text
rspec /tmp/d20160107-5693-16w75z4/spec.rb:420 # LazyMode#where filters by header text
rspec /tmp/d20160107-5693-16w75z4/spec.rb:432 # LazyMode#where filters by status
rspec /tmp/d20160107-5693-16w75z4/spec.rb:443 # LazyMode#where filters by multiple filters

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

Христина обнови решението на 21.12.2015 01:04 (преди над 8 години)

+class LazyMode
+
+ def initialize
+ @new_file
+ end
+
+ class Date
+
+ def initialize(string)
+ @date = string.split('-')
+ end
+
+ def year
+ @date[0].to_i
+ end
+
+ def month
+ @date[1].to_i
+ end
+
+ def day
+ @date[2].to_i
+ end
+
+ def to_s
+ ("0" * (4 - year.to_s.length)) << "#{year}-" <<
+ ("0" * (2 - month.to_s.length)) << "#{month}-" <<
+ ("0" * (2 - day.to_s.length)) << "#{day}"
+ end
+
+ end
+
+ def self.create_file(name, &block)
+ @new_file = File.new(name, &block)
+ @new_file
+ end
+
+ class Note
+
+ def initialize(title, keeper, args)
+ @title = title
+ @keeper = keeper
+ @content = ""
+ @status = :topostpone
+ @args = args
+ @date
+ end
+
+ def header
+ @title
+ end
+
+ def file_name
+ @keeper
+ end
+
+ def body(string = nil)
+ if string != nil
+ @content = string
+ else
+ @content
+ end
+ end
+
+ def status(status = nil)
+ if status != nil
+ @status = status
+ else
+ @status
+ end
+ end
+
+ def tags
+ @args
+ end
+
+ def scheduled(date = nil)
+ if date != nil && date.size > 10
+ @date = Date.new(date[0...date.index('+') - 1])
+ elsif date != nil
+ @date = date
+ else
+ @date
+ end
+ end
+
+ def date
+ scheduled.to_s
+ end
+
+ end
+
+ class File
+
+ def initialize(name, &block)
+ @name = name
+ @notes = []
+ self.instance_eval(&block)
+ end
+
+ def note(title, *args, &var)
+ current_file = @name
+ new_note = Note.new(title, current_file, args)
+ new_note.instance_exec(&var) if block_given?
+ @notes << new_note
+ end
+
+ def name
+ @name
+ end
+
+ def notes
+ @notes
+ end
+
+ def daily_agenda(date)
+ notes = @notes
+ DailyAgendaReturnObject.new(date, notes)
+ end
+
+ def weekly_agenda(date)
+ notes = @notes
+ WeeklyAgendaReturnObject.new(date, notes)
+ end
+
+ class DailyAgendaReturnObject
+
+ def initialize(given_date, notes)
+ @notes = notes.reject{ |x| x.date != given_date.to_s }
+ end
+
+ def notes
+ @notes
+ end
+
+ def where
+ end
+
+ end
+
+ class WeeklyAgendaReturnObject
+
+ def initialize(given_date, notes)
+ end
+
+ def notes
+ @notes
+ end
+
+ def where
+ end
+
+ end
+
+ end
+
+end

Христина обнови решението на 21.12.2015 11:35 (преди над 8 години)

class LazyMode
def initialize
@new_file
end
class Date
def initialize(string)
@date = string.split('-')
end
def year
@date[0].to_i
end
def month
@date[1].to_i
end
def day
@date[2].to_i
end
def to_s
("0" * (4 - year.to_s.length)) << "#{year}-" <<
("0" * (2 - month.to_s.length)) << "#{month}-" <<
("0" * (2 - day.to_s.length)) << "#{day}"
end
+ def add_day
+ if day == 30
+ @date[2] = 1.to_s
+ add_month
+ else
+ @date[2] = (day + 1).to_s
+ end
+ end
+
+ def add_month
+ if month == 12
+ @date[1] = 1.to_s
+ add_year
+ else
+ @date[1] = (month + 1).to_s
+ end
+ end
+
+ def add_year
+ @date[0] = (year + 1).to_s
+ end
+
end
def self.create_file(name, &block)
@new_file = File.new(name, &block)
@new_file
end
- class Note
+ module More
- def initialize(title, keeper, args)
- @title = title
- @keeper = keeper
- @content = ""
- @status = :topostpone
- @args = args
- @date
- end
-
- def header
- @title
- end
-
- def file_name
- @keeper
- end
-
def body(string = nil)
- if string != nil
- @content = string
- else
- @content
- end
+ string != nil ? @content = string : @content
end
def status(status = nil)
- if status != nil
- @status = status
- else
- @status
- end
+ status != nil ? @status = status : @status
end
- def tags
- @args
- end
-
def scheduled(date = nil)
if date != nil && date.size > 10
@date = Date.new(date[0...date.index('+') - 1])
elsif date != nil
@date = date
else
@date
end
end
def date
- scheduled.to_s
+ scheduled
end
end
+ class Note
+
+ include More
+
+ def initialize(*args)
+ @args = args
+ @content = ""
+ @status = :topostpone
+ @date
+ @in_notes = []
+ end
+
+ def header
+ @args[0]
+ end
+
+ def file_name
+ @args[1]
+ end
+
+ def tags
+ @args.last
+ end
+
+ def note(title = nil , *args, &var)
+ if block_given?
+ current_file = @args[1]
+ new_note = Note.new(title, current_file, args)
+ new_note.instance_exec(&var)
+ @in_notes << new_note
+ else
+ @in_notes
+ end
+ end
+
+ end
+
class File
def initialize(name, &block)
@name = name
@notes = []
self.instance_eval(&block)
end
def note(title, *args, &var)
current_file = @name
new_note = Note.new(title, current_file, args)
new_note.instance_exec(&var) if block_given?
@notes << new_note
end
def name
@name
end
def notes
@notes
end
def daily_agenda(date)
notes = @notes
DailyAgendaReturnObject.new(date, notes)
end
def weekly_agenda(date)
notes = @notes
WeeklyAgendaReturnObject.new(date, notes)
end
class DailyAgendaReturnObject
def initialize(given_date, notes)
- @notes = notes.reject{ |x| x.date != given_date.to_s }
+ @notes = notes.reject{ |x| x.date.to_s != given_date.to_s }
+ #inside_notes(given_date, notes)
+ @notes
end
-
+=begin
+ def inside_notes(given_date, notes)
+ notes.each do |new_note|
+ new_notes = new_note.note.reject{ |x| x.date.to_s !=
+ given_date.to_s }
+ @notes.concat(new_notes)
+ end
+ end
+=end
def notes
@notes
end
def where
end
end
class WeeklyAgendaReturnObject
def initialize(given_date, notes)
+ @notes = []
+ # 7.times do
+ # @notes.concat(notes.reject{ |x| x.date.to_s != given_date.to_s })
+ # given_date.add_day
+ # end
+ #inside_notes(given_date, notes)
+ @notes
end
-
+=begin
+ def inside_notes(given_date, notes)
+ check = given_date
+ notes.each do |new_note|
+ 7.times do
+ new_notes = new_note.note.reject{ |x| x.date.to_s !=
+ check.to_s }
+ @notes.concat(new_notes)
+ check.add_day
+ end
+ check = given_date
+ end
+ end
+=end
def notes
@notes
end
def where
end
end
end
end