Решение на Седма задача от Клара Кайралах

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

Към профила на Клара Кайралах

Резултати

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

Код

module LazyMode
def self.file_name
@file_name
end
def self.create_file(file_name, &block)
@file_name = file_name
Note.instance_eval &block
File.new(file_name, Note.notes)
end
class Date
def initialize(date_string)
@year, @month, @day = * date_string.split("-")
year
month
day
end
def converting(var)
var.insert(0,"0") if var.size % 2 != 0
var.to_i
end
def year
converting(@year)
end
def month
converting(@month)
end
def day
converting(@day)
end
def to_s
"#{@year}-#{@month}-#{@day}"
end
def ==(other_date)
return true if self.year == other_date.year &&
self.month == other_date.month &&
self.day == other_date.day
false
end
end
class Agenda
def initialize(notes = [])
@notes = notes
end
def add_notes(note)
@notes.push(note)
end
def notes
@notes.flatten.reverse
end
end
class File
def initialize(file_name, notes)
@file_name = file_name
@notes = notes
end
attr_reader :file_name
def name
@file_name
end
def notes
@notes
end
def daily_agenda(date)
agenda = Agenda.new
agenda.add_notes(Note::get_notes(date)) if Note::get_notes(date) != []
agenda
end
def weekly_agenda(date)
agenda, data = Agenda.new, date
7.times{
note = Note::get_notes(data)
agenda.add_notes(note)
data = Date.new("#{data.year}-#{data.month}-#{data.day + 1}")
}
agenda
end
end
class ScheduleHelper
def self.multiple_schedule(date, type)
hash_day_month, day, month = {d: 1,w: 7},date.day,date.month + 1
if type != 'm'
day = day + hash_day_month[type.to_sym]
month = date.month - 2
end
day = day - 30 if day > 30
LazyMode::Date.new("#{date.year}-#{month}-#{day}")
end
def self.schedule_helper(date)
date_and_period, scheduled = date.split(' '), []
date = Date.new(date_and_period[0])
date_and_period[1][1].to_i.times do
date = ScheduleHelper::multiple_schedule(date, date_and_period[1][2])
scheduled.push(date)
end
scheduled
end
end
class Note
def initialize(header, body, tags, status)
@header = header
@status = :topostpone if @status.nil?
@body = "" if @body.nil?
@tags = tags
@file_name = LazyMode.file_name
@scheduled, @date = scheduled, date
end
attr_reader :status, :body, :file_name, :scheduled, :date, :tags, :notes
attr_accessor :header
def self.note(header, *tags, &block)
@notes = [] if @notes.nil?
self.instance_eval &block
@notes.push(Note.new(header, @body, [*tags], @status))
end
def self.body(body)
@body = body
@body
end
def self.status(status)
@status = status
@status
end
def self.notes
@notes
end
def is_equal_notes(note, notes, date)
scheduled = note.scheduled.first if note.scheduled.is_a?(Array)
notes.push(Note.new(note.header,note.body,note.status,note.tags,
note.scheduled, note.file_name,
note.date)) if scheduled == date.to_s
end
def self.get_notes(date, notes = [], scheduled = @scheduled)
@notes.each { |note|
is_equal_notes(note, notes, date, scheduled)
}
notes.reverse
end
def self.scheduled(date)
if ! date.split(' ')[1].nil?
@scheduled,@date = ScheduleHelper::schedule_helper(date), date
return @scheduled.first
else
@date = LazyMode::Date.new(date)
@scheduled = @date.to_s
end
@scheduled
end
end
end

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

....F.F.F.F.FFFFFFFFFFFFFFFFF.F

Failures:

  1) LazyMode LazyMode::Note has header
     Failure/Error: expect(file.notes.first.header).to eq('todo_list')
       
       expected: "todo_list"
            got: "one"
       
       (compared using ==)
     # /tmp/d20160107-5693-c5flop/spec.rb:35: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 #tags has tags
     Failure/Error: expect(file.notes.first.tags).to eq([:important, :wip, :blocker])
       
       expected: [:important, :wip, :blocker]
            got: []
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -[:important, :wip, :blocker]
       +[]
     # /tmp/d20160107-5693-c5flop/spec.rb:45: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 has status
     Failure/Error: expect(file.notes.first.status).to eq(:postponed)
       
       expected: :postponed
            got: :topostpone
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:postponed
       +:topostpone
     # /tmp/d20160107-5693-c5flop/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)>'

  4) LazyMode LazyMode::Note #body has body
     Failure/Error: expect(file.notes.first.body).to eq('Do not forget to...')
       
       expected: "Do not forget to..."
            got: ""
       
       (compared using ==)
     # /tmp/d20160107-5693-c5flop/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#daily_agenda returns note scheduled without repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  6) LazyMode#daily_agenda returns note scheduled with daily repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  7) LazyMode#daily_agenda returns note scheduled with weekly repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  8) LazyMode#daily_agenda returns note scheduled with monthly repeater
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2013-01-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  9) 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 `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  10) LazyMode#daily_agenda returns nested notes
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-08-06'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  11) LazyMode#weekly_agenda returns note scheduled without repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-12-06'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:92:in `block in weekly_agenda'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `times'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `weekly_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  12) 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 `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:92:in `block in weekly_agenda'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `times'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `weekly_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  13) LazyMode#weekly_agenda returns note scheduled with weekly repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-12-10'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:92:in `block in weekly_agenda'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `times'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `weekly_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  14) LazyMode#weekly_agenda returns note scheduled with monthly repeater
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2013-01-10'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:92:in `block in weekly_agenda'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `times'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `weekly_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  15) 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 `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:92:in `block in weekly_agenda'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `times'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `weekly_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  16) LazyMode#weekly_agenda returns nested notes
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-09-05'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:92:in `block in weekly_agenda'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `times'
     # /tmp/d20160107-5693-c5flop/solution.rb:91:in `weekly_agenda'
     # /tmp/d20160107-5693-c5flop/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)>'

  17) LazyMode#where filters by tag
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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 body text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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 header text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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 status
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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 multiple filters
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `is_equal_notes' for LazyMode::Note:Class
     # /tmp/d20160107-5693-c5flop/solution.rb:165:in `block in get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `each'
     # /tmp/d20160107-5693-c5flop/solution.rb:164:in `get_notes'
     # /tmp/d20160107-5693-c5flop/solution.rb:85:in `daily_agenda'
     # /tmp/d20160107-5693-c5flop/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.create_file can build notes in the block
     Failure/Error: expect(file.notes.size).to eq(3)
       
       expected: 3
            got: 52
       
       (compared using ==)
     # /tmp/d20160107-5693-c5flop/spec.rb:477: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.01833 seconds
31 examples, 22 failures

Failed examples:

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

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

Клара обнови решението на 21.12.2015 17:21 (преди над 8 години)

+module LazyMode
+
+ def self.file_name
+ @file_name
+ end
+
+ def self.create_file(file_name, &block)
+ @file_name = file_name
+ Note.instance_eval &block
+ File.new(file_name, Note.notes)
+ end
+
+ class Date
+
+ def initialize(date_string)
+ @year, @month, @day = * date_string.split("-")
+ year
+ month
+ day
+ end
+
+ def converting(var)
+ var.insert(0,"0") if var.size % 2 != 0
+ var.to_i
+ end
+
+ def year
+ converting(@year)
+ end
+
+ def month
+ converting(@month)
+ end
+
+ def day
+ converting(@day)
+ end
+
+ def to_s
+ "#{@year}-#{@month}-#{@day}"
+ end
+
+ def ==(other_date)
+ return true if self.year == other_date.year &&
+ self.month == other_date.month &&
+ self.day == other_date.day
+ false
+ end
+ end
+
+ class Agenda
+
+ def initialize(notes = [])
+ @notes = notes
+ end
+
+ def add_notes(note)
+ @notes.push(note)
+ end
+
+ def notes
+ @notes.flatten.reverse
+ end
+ end
+
+ class File
+
+ def initialize(file_name, notes)
+ @file_name = file_name
+ @notes = notes
+ end
+
+ attr_reader :file_name
+
+ def name
+ @file_name
+ end
+
+ def notes
+ @notes
+ end
+
+ def daily_agenda(date)
+ agenda = Agenda.new
+ agenda.add_notes(Note::get_notes(date)) if Note::get_notes(date) != []
+ agenda
+ end
+
+ def weekly_agenda(date)
+ agenda, data = Agenda.new, date
+ 7.times{
+ note = Note::get_notes(data)
+ agenda.add_notes(note)
+ data = Date.new("#{data.year}-#{data.month}-#{data.day + 1}")
+ }
+ agenda
+ end
+ end
+
+ class ScheduleHelper
+ def self.multiple_schedule(date, type)
+ hash_day_month, day, month = {d: 1,w: 7},date.day,date.month + 1
+ if type != 'm'
+ day = day + hash_day_month[type.to_sym]
+ month = date.month - 2
+ end
+ day = day - 30 if day > 30
+ LazyMode::Date.new("#{date.year}-#{month}-#{day}")
+ end
+
+ def self.schedule_helper(date)
+ date_and_period, scheduled = date.split(' '), []
+ date = Date.new(date_and_period[0])
+ date_and_period[1][1].to_i.times do
+ date = ScheduleHelper::multiple_schedule(date, date_and_period[1][2])
+ scheduled.push(date)
+ end
+ scheduled
+ end
+ end
+
+ class Note
+
+ def initialize(header, body, tags, status)
+ @header = header
+ @status = :topostpone if @status.nil?
+ @body = "" if @body.nil?
+ @tags = tags
+ @file_name = LazyMode.file_name
+ @scheduled, @date = scheduled, date
+ end
+
+ attr_reader :status, :body, :file_name, :scheduled, :date, :tags, :notes
+ attr_accessor :header
+
+ def self.note(header, *tags, &block)
+ @notes = [] if @notes.nil?
+ self.instance_eval &block
+ @notes.push(Note.new(header, @body, [*tags], @status))
+ end
+
+ def self.body(body)
+ @body = body
+ @body
+ end
+
+ def self.status(status)
+ @status = status
+ @status
+ end
+
+ def self.notes
+ @notes
+ end
+
+ def is_equal_notes(note, notes, date)
+ scheduled = note.scheduled.first if note.scheduled.is_a?(Array)
+ notes.push(Note.new(note.header,note.body,note.status,note.tags,
+ note.scheduled, note.file_name,
+ note.date)) if scheduled == date.to_s
+ end
+
+ def self.get_notes(date, notes = [], scheduled = @scheduled)
+ @notes.each { |note|
+ is_equal_notes(note, notes, date, scheduled)
+ }
+ notes.reverse
+ end
+
+ def self.scheduled(date)
+ if ! date.split(' ')[1].nil?
+ @scheduled,@date = ScheduleHelper::schedule_helper(date), date
+ return @scheduled.first
+ else
+ @date = LazyMode::Date.new(date)
+ @scheduled = @date.to_s
+ end
+ @scheduled
+ end
+
+ end
+end