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

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

Към профила на Александрина Каракехайова

Резултати

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

Код

module LazyMode
def self.create_file(name, &block)
object = File.new(name)
object.instance_eval &block
object
end
class Date
def initialize(date)
@date = date
@day = date.split('-')[2].to_i
@month = date.split('-')[1].to_i
@year = date.split('-')[0].to_i
end
def year
@year
end
def month
@month
end
def day
@day
end
def add_day
if @day == 30 and @month == 12
@day, @month = 1, 1
@year += 1
elsif @day == 30
@day, @month = 1, @month + 1
else @day += 1
end
end
def to_s
@date.split('-')[2].insert(0, '0') if @date.split('-')[2].length < 2
@date.split('-')[1].insert(0, '0') if @date.split('-')[1].length < 2
@date.split('-')[0].insert(0, '0') if @date.split('-')[0].length < 4
@date
end
end
class Note
attr_accessor :file_name, :body, :status, :header, :date, :period
def initialize(header, *tags, status, body)
@header = header
@body = body
@status = status
@tags = *tags.flatten
@file_name = ''
@period = 0
end
def copy(date)
object = Note.new(@header, @tags, @status, @body)
object.date = date
object
end
def tags
@tags
end
end
class MainNote
attr_accessor :date, :all_notes
def initialize(header, *tags)
@header = header
@tags = *tags.flatten
@status = :topostpone
@period = 0
end
def scheduled(period)
date = period.split('+')
@date = Date.new(date[0].chomp)
@period = define_period(date) if date.size == 2
end
def note(header, *tags, &block)
object = MainNote.new(header, *tags)
object.all_notes = @all_notes
object.instance_eval &block if block_given?
note = object.return_note
note.file_name = @name
@all_notes.push(note)
end
def define_period(date)
case date[1].chars.last
when 'w' then date[1].chars.first.to_i * 7
when 'd' then date[1].chars.first.to_i
when 'm' then date[1].chars.first.to_i * 30
end
end
def status(status)
@status = status
end
def body(body)
@body = body
end
def return_note
object = Note.new(@header, @tags, @status, @body)
object.date = @date
object.period = @period
object
end
end
class File
attr_accessor :all_notes
attr_reader :name
def initialize(name)
@name = name
@all_notes = []
end
def note(header, *tags, &block)
object = MainNote.new(header, *tags)
object.all_notes = @all_notes
object.instance_eval &block if block_given?
note = object.return_note
note.file_name = @name
@all_notes.push(note)
end
def notes
@all_notes
end
def daily_agenda(date)
DailyAgenda.new(date, @all_notes)
end
def weekly_agenda(date)
WeeklyAgenda.new(date, @all_notes)
end
def where
end
end
class Agenda
def initialize(date, all_notes)
@date = date
@all_notes = all_notes
@notes = []
end
def notes
@all_notes.each { |note| check_dates(note.date, note) }
@notes
end
def date_difference(date)
year = (@date.year - date.year) * 360
month = (@date.month - date.month) * 30
day = (@date.day - date.day)
year + month + day
end
def check_dates(date, note)
if (note.period != 0) and date_difference(date) % note.period == 0
@notes.push(note.copy(@date))
end
end
end
class DailyAgenda < Agenda
def notes
@all_notes.each { |note| check_dates(note.date, note) }
@notes
end
end
class WeeklyAgenda < Agenda
def notes
(0...7).each do
@notes += DailyAgenda.new(@date, @all_notes).notes
@date = @date.add_day
end
@notes
end
end
end

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

.....F.....FF...FFFFFFFFFFFFF..

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-4ula4w/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-4ula4w/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: expect(agenda.notes.size).to eq(1)
       
       expected: 1
            got: 0
       
       (compared using ==)
     # /tmp/d20160107-5693-4ula4w/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)>'

  4) LazyMode#daily_agenda does not return note whose start date is in the future
     Failure/Error: expect(agenda.notes.size).to eq(0)
       
       expected: 0
            got: 1
       
       (compared using ==)
     # /tmp/d20160107-5693-4ula4w/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)>'

  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-4ula4w/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)
     NoMethodError:
       undefined method `add_day' for 7:Fixnum
     # /tmp/d20160107-5693-4ula4w/solution.rb:186:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `notes'
     # /tmp/d20160107-5693-4ula4w/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)
     NoMethodError:
       undefined method `year' for 7:Fixnum
     # /tmp/d20160107-5693-4ula4w/solution.rb:162:in `date_difference'
     # /tmp/d20160107-5693-4ula4w/solution.rb:169:in `check_dates'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:185:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `notes'
     # /tmp/d20160107-5693-4ula4w/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)
     NoMethodError:
       undefined method `year' for 11:Fixnum
     # /tmp/d20160107-5693-4ula4w/solution.rb:162:in `date_difference'
     # /tmp/d20160107-5693-4ula4w/solution.rb:169:in `check_dates'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:185:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `notes'
     # /tmp/d20160107-5693-4ula4w/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)
     NoMethodError:
       undefined method `year' for 11:Fixnum
     # /tmp/d20160107-5693-4ula4w/solution.rb:162:in `date_difference'
     # /tmp/d20160107-5693-4ula4w/solution.rb:169:in `check_dates'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:185:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `notes'
     # /tmp/d20160107-5693-4ula4w/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 does not return note whose start date is in the future
     Failure/Error: expect(agenda.notes.size).to eq(0)
     NoMethodError:
       undefined method `year' for 13:Fixnum
     # /tmp/d20160107-5693-4ula4w/solution.rb:162:in `date_difference'
     # /tmp/d20160107-5693-4ula4w/solution.rb:169:in `check_dates'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:185:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `notes'
     # /tmp/d20160107-5693-4ula4w/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)>'

  11) LazyMode#weekly_agenda returns nested notes
     Failure/Error: expect(agenda.notes.size).to eq(1)
     NoMethodError:
       undefined method `year' for 6:Fixnum
     # /tmp/d20160107-5693-4ula4w/solution.rb:162:in `date_difference'
     # /tmp/d20160107-5693-4ula4w/solution.rb:169:in `check_dates'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:177:in `notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:185:in `block in notes'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `each'
     # /tmp/d20160107-5693-4ula4w/solution.rb:184:in `notes'
     # /tmp/d20160107-5693-4ula4w/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)>'

  12) LazyMode#where filters by tag
     Failure/Error: notes = @agenda.where(tag: :important).notes
     NoMethodError:
       undefined method `where' for #<LazyMode::DailyAgenda:0x007f8f2a8371e0>
     # /tmp/d20160107-5693-4ula4w/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)>'

  13) LazyMode#where filters by body text
     Failure/Error: notes = @agenda.where(text: /Very/).notes
     NoMethodError:
       undefined method `where' for #<LazyMode::DailyAgenda:0x007f8f2a8aee70>
     # /tmp/d20160107-5693-4ula4w/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)>'

  14) LazyMode#where filters by header text
     Failure/Error: notes = @agenda.where(text: /not important/).notes
     NoMethodError:
       undefined method `where' for #<LazyMode::DailyAgenda:0x007f8f2a899778>
     # /tmp/d20160107-5693-4ula4w/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)>'

  15) LazyMode#where filters by status
     Failure/Error: notes = @agenda.where(status: :postponed).notes
     NoMethodError:
       undefined method `where' for #<LazyMode::DailyAgenda:0x007f8f2a895ab0>
     # /tmp/d20160107-5693-4ula4w/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)>'

  16) LazyMode#where filters by multiple filters
     Failure/Error: notes = @agenda.where(text: /important/, status: :postponed).notes
     NoMethodError:
       undefined method `where' for #<LazyMode::DailyAgenda:0x007f8f2a891c08>
     # /tmp/d20160107-5693-4ula4w/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.01798 seconds
31 examples, 16 failures

Failed examples:

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

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

Александрина обнови решението на 18.12.2015 20:46 (преди около 9 години)

+module LazyMode
+
+ def self.create_file(name, &block)
+ object = File.new(name)
+ object.instance_eval &block if block_given?
+ object
+ end
+
+ class Date
+ def initialize (date)
+ @date = date
+ @day = date.split('-')[2]
+ @month = date.split('-')[1]
+ @year = date.split('-')[0]
+ end
+
+ def year
+ zeros = 4 - @year.length
+ zeros.times do @year.insert(0, '0')
+ end
+ @year.to_i
+ end
+
+ def month
+ zeros = 2 - @month.length
+ zeros.times do @month.insert(0, '0')
+ end
+ @month.to_i
+ end
+
+ def day
+ zeros = 2 - @day.length
+ zeros.times do @day.insert(0, '0')
+ end
+ @day.to_i
+ end
+
+ def add_day
+ new_date = @date
+ end_of_month = new_date.day == 30
+ end_of_year = end_of_month && new_date.month == 12
+ end
+
+ def to_s
+ @date
+ end
+ end
+
+ class Note
+ attr_accessor :file_name, :body, :status, :header, :date, :period
+ def initialize(header, *tags,status,body)
+ @header = header
+ @body = body
+ @status = status
+ @tags = *tags.flatten
+ @file_name = ""
+ @period = 0
+ end
+
+ def copy(date)
+ object = Note.new(@header,@tags,@status,@body)
+ object.date = date
+ object
+ end
+
+ def tags
+ @tags
+ end
+ end
+
+ class MainNote
+ attr_accessor :date, :all_notes
+ def initialize(header, *tags)
+ @header = header
+ @tags = *tags.flatten
+ @status = :topostpone
+ @period = 0
+ end
+
+ def scheduled(period)
+ date = period.split('+')
+ @date = Date.new(date[0].chomp)
+ @period = define_period(date) if date.size == 2
+ end
+
+ def note(header, *tags, &block)
+ object = MainNote.new(header, *tags)
+ object.all_notes = @all_notes
+ object.instance_eval &block if block_given?
+ note = object.return_note
+ note.file_name = @name
+ @all_notes.push(note)
+ end
+
+ def define_period(date)
+ case date[1].chars.last
+ when "w" then date[1].chars.first.to_i * 7
+ when "d" then date[1].chars.first.to_i
+ when "m" then date[1].chars.first.to_i * 30
+ end
+ end
+
+ def status (status)
+ @status = status
+ end
+
+ def body(body)
+ @body = body
+ end
+
+ def return_note
+ object = Note.new(@header,@tags,@status,@body)
+ object.date = @date
+ object.period = @period
+ object
+ end
+ end
+
+
+ class File
+ attr_accessor :all_notes
+ attr_reader :name
+ def initialize(name)
+ @name = name
+ @all_notes = []
+ end
+
+ def note(header, *tags, &block)
+ object = MainNote.new(header, *tags)
+ object.all_notes = @all_notes
+ object.instance_eval &block if block_given?
+ note = object.return_note
+ note.file_name = @name
+ @all_notes.push(note)
+ end
+
+ def notes
+ @all_notes
+ end
+
+ def daily_agenda(date)
+ DailyAgenda.new(date, @all_notes)
+ end
+
+ def weekly_agenda(date)
+ WeeklyAgenda.new(date, @all_notes)
+ end
+
+ def where
+ end
+ end
+
+ class Agenda
+
+ def initialize(date, all_notes)
+ @date = date
+ @all_notes = all_notes
+ @notes = []
+ end
+
+ def notes()
+ @all_notes.each { |note| check_dates(note.date,note) }
+ @notes
+ end
+
+ def date_difference(date)
+ year = (@date.year - date.year) * 360
+ month = (@date.month - date.month) * 30
+ day = (@date.day - date.day)
+ year + month + day
+ end
+
+ def check_dates(date,note)
+ if (note.period != 0) and date_difference(date) % note.period == 0
+ @notes.push(note.copy(@date))
+ end
+ end
+ end
+
+ class DailyAgenda < Agenda
+ def notes()
+ @all_notes.each { |note| check_dates(note.date,note) }
+ @notes
+ end
+ end
+
+ class WeeklyAgenda < Agenda
+ def notes()
+ (0...7).each do
+ @notes + DailyAgenda(@date, @all_notes).notes
+ @date = @date.add_day
+ end
+ end
+ end
+end

Александрина обнови решението на 21.12.2015 11:35 (преди около 9 години)

module LazyMode
-
- def self.create_file(name, &block)
+ def self.create_file(name, &block)
object = File.new(name)
- object.instance_eval &block if block_given?
+ object.instance_eval &block
object
- end
+ end
class Date
- def initialize (date)
+ def initialize(date)
@date = date
- @day = date.split('-')[2]
- @month = date.split('-')[1]
- @year = date.split('-')[0]
+ @day = date.split('-')[2].to_i
+ @month = date.split('-')[1].to_i
+ @year = date.split('-')[0].to_i
end
def year
- zeros = 4 - @year.length
- zeros.times do @year.insert(0, '0')
- end
- @year.to_i
+ @year
end
def month
- zeros = 2 - @month.length
- zeros.times do @month.insert(0, '0')
- end
- @month.to_i
+ @month
end
def day
- zeros = 2 - @day.length
- zeros.times do @day.insert(0, '0')
- end
- @day.to_i
+ @day
end
def add_day
- new_date = @date
- end_of_month = new_date.day == 30
- end_of_year = end_of_month && new_date.month == 12
+ if @day == 30 and @month == 12
+ @day, @month = 1, 1
+ @year += 1
+ elsif @day == 30
+ @day, @month = 1, @month + 1
+ else @day += 1
+ end
end
def to_s
+ @date.split('-')[2].insert(0, '0') if @date.split('-')[2].length < 2
+ @date.split('-')[1].insert(0, '0') if @date.split('-')[1].length < 2
+ @date.split('-')[0].insert(0, '0') if @date.split('-')[0].length < 4
@date
end
end
class Note
attr_accessor :file_name, :body, :status, :header, :date, :period
- def initialize(header, *tags,status,body)
+ def initialize(header, *tags, status, body)
@header = header
@body = body
@status = status
@tags = *tags.flatten
- @file_name = ""
+ @file_name = ''
@period = 0
end
def copy(date)
- object = Note.new(@header,@tags,@status,@body)
+ object = Note.new(@header, @tags, @status, @body)
object.date = date
object
end
def tags
@tags
end
end
class MainNote
- attr_accessor :date, :all_notes
- def initialize(header, *tags)
+ attr_accessor :date, :all_notes
+ def initialize(header, *tags)
@header = header
@tags = *tags.flatten
@status = :topostpone
@period = 0
end
def scheduled(period)
date = period.split('+')
@date = Date.new(date[0].chomp)
@period = define_period(date) if date.size == 2
end
def note(header, *tags, &block)
object = MainNote.new(header, *tags)
object.all_notes = @all_notes
object.instance_eval &block if block_given?
note = object.return_note
note.file_name = @name
@all_notes.push(note)
end
def define_period(date)
case date[1].chars.last
- when "w" then date[1].chars.first.to_i * 7
- when "d" then date[1].chars.first.to_i
- when "m" then date[1].chars.first.to_i * 30
- end
+ when 'w' then date[1].chars.first.to_i * 7
+ when 'd' then date[1].chars.first.to_i
+ when 'm' then date[1].chars.first.to_i * 30
+ end
end
- def status (status)
+ def status(status)
@status = status
end
def body(body)
- @body = body
+ @body = body
end
def return_note
- object = Note.new(@header,@tags,@status,@body)
- object.date = @date
- object.period = @period
- object
+ object = Note.new(@header, @tags, @status, @body)
+ object.date = @date
+ object.period = @period
+ object
end
end
-
class File
attr_accessor :all_notes
attr_reader :name
def initialize(name)
@name = name
@all_notes = []
end
def note(header, *tags, &block)
object = MainNote.new(header, *tags)
object.all_notes = @all_notes
object.instance_eval &block if block_given?
note = object.return_note
note.file_name = @name
@all_notes.push(note)
end
def notes
@all_notes
end
def daily_agenda(date)
DailyAgenda.new(date, @all_notes)
end
def weekly_agenda(date)
WeeklyAgenda.new(date, @all_notes)
end
def where
end
end
class Agenda
-
def initialize(date, all_notes)
@date = date
@all_notes = all_notes
@notes = []
end
- def notes()
- @all_notes.each { |note| check_dates(note.date,note) }
+ def notes
+ @all_notes.each { |note| check_dates(note.date, note) }
@notes
end
def date_difference(date)
year = (@date.year - date.year) * 360
month = (@date.month - date.month) * 30
day = (@date.day - date.day)
year + month + day
end
- def check_dates(date,note)
+ def check_dates(date, note)
if (note.period != 0) and date_difference(date) % note.period == 0
- @notes.push(note.copy(@date))
- end
+ @notes.push(note.copy(@date))
+ end
end
end
class DailyAgenda < Agenda
- def notes()
- @all_notes.each { |note| check_dates(note.date,note) }
- @notes
+ def notes
+ @all_notes.each { |note| check_dates(note.date, note) }
+ @notes
end
end
class WeeklyAgenda < Agenda
- def notes()
+ def notes
(0...7).each do
- @notes + DailyAgenda(@date, @all_notes).notes
+ @notes += DailyAgenda.new(@date, @all_notes).notes
@date = @date.add_day
end
+ @notes
end
end
-end
+end