Решение на Седма задача от Малина Демирова

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

Към профила на Малина Демирова

Резултати

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

Код

module LazyMode
class Date
attr_reader :date
def initialize(date)
@date = date
end
def year
current_year = @date.to_s.split('-').first
if(current_year.to_i < 1000)
current_year.to_s.insert(0,'0')
end
current_year
end
def month
current_month = @date.to_s.split('-')[1]
if(current_month.to_i < 10)
current_month.to_s.insert(0,'0')
end
current_month
end
def day
current_day = @date.to_s.split('-').last
if(current_day.to_i < 10)
current_day.to_s.insert(0,'0')
end
current_day
end
def to_s
"#{year}-#{month}-#{day}"
end
end
class Note < Struct.new(:header, :body, :status, :tags)
def self.new_note(header, body, status, tags)
Note.new(header.strip.downcase.to_sym,
body.strip,
status.strip.downcase.to_sym,
tags.split(',').map(&:strip))
end
end
class File
def initialize(name, notes = [])
@notes = notes
@name = name
end
def each(&block)
@notes.each &block
end
def self.create_file(name = File.new.name)
@notes[name] = notes
end
def self.name
file_name = "#{@name}"
end
def note
notes = Note.new_note
header = "#{@notes.header}"
tags = "#{@notes.tags}".join(" , ")
status = "#{@notes.status}"
body = "#{@notes.body}"
size = @notes.size
end
def scheduled(some_date)
current_date = LazyMode::Date.new(some_date)
scheduled_date = current_date
case occurence
when 'm' then end_date = current_date.month + 1
when 'd' then end_date = current_date.day + 1
when 'w' then end_date = current_date.day + 7
end
end
def serialize
file = "#{@notes.size}:#{serialize_entities(@name)}"
"#{file}"
end
protected
attr_reader :notes, :name
end
def self.create_file(name = File.new.name)
end
end

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

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) LazyMode LazyMode::Date can parse year
     Failure/Error: expect(date.year).to eq(2012)
       
       expected: 2012
            got: "2012"
       
       (compared using ==)
     # /tmp/d20160107-5693-17v3ks6/spec.rb:5: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::Date can parse month
     Failure/Error: expect(date.month).to eq(10)
       
       expected: 10
            got: "10"
       
       (compared using ==)
     # /tmp/d20160107-5693-17v3ks6/spec.rb:10: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 LazyMode::Date can parse day
     Failure/Error: expect(date.day).to eq(3)
       
       expected: 3
            got: "003"
       
       (compared using ==)
     # /tmp/d20160107-5693-17v3ks6/spec.rb:15: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 LazyMode::Note has file_name
     Failure/Error: expect(file.notes.first.file_name).to eq('my_todos')
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/spec.rb:26: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 LazyMode::Note has header
     Failure/Error: expect(file.notes.first.header).to eq('todo_list')
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  6) LazyMode LazyMode::Note can have nested notes
     Failure/Error: expect(file.notes.first.body).to eq('')
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  7) LazyMode LazyMode::Note #tags has tags
     Failure/Error: expect(file.notes.first.tags).to eq([:important, :wip, :blocker])
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  8) LazyMode LazyMode::Note #tags can have no tags
     Failure/Error: expect(file.notes.first.tags).to eq([])
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/spec.rb:54: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)>'

  9) LazyMode LazyMode::Note #status has status
     Failure/Error: expect(file.notes.first.status).to eq(:postponed)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  10) LazyMode LazyMode::Note #status can have default status
     Failure/Error: expect(file.notes.first.status).to eq(:topostpone)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  11) LazyMode LazyMode::Note #body has body
     Failure/Error: expect(file.notes.first.body).to eq('Do not forget to...')
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  12) LazyMode LazyMode::Note #body can have no body
     Failure/Error: expect(file.notes.first.body).to eq('')
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  13) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  14) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  15) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  16) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  17) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  18) LazyMode#daily_agenda returns nested notes
     Failure/Error: agenda = file.daily_agenda(LazyMode::Date.new('2012-08-06'))
     NoMethodError:
       undefined method `daily_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  19) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  20) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  21) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  22) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  23) 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 nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  24) LazyMode#weekly_agenda returns nested notes
     Failure/Error: agenda = file.weekly_agenda(LazyMode::Date.new('2012-09-05'))
     NoMethodError:
       undefined method `weekly_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  25) LazyMode#where filters by tag
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  26) LazyMode#where filters by body text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  27) LazyMode#where filters by header text
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  28) LazyMode#where filters by status
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  29) LazyMode#where filters by multiple filters
     Failure/Error: @agenda = file.daily_agenda(LazyMode::Date.new('2012-12-12'))
     NoMethodError:
       undefined method `daily_agenda' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  30) LazyMode.create_file can assign name to files
     Failure/Error: expect(file.name).to eq('important_notes_and_todos')
     NoMethodError:
       undefined method `name' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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)>'

  31) LazyMode.create_file can build notes in the block
     Failure/Error: expect(file.notes.size).to eq(3)
     NoMethodError:
       undefined method `notes' for nil:NilClass
     # /tmp/d20160107-5693-17v3ks6/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.01307 seconds
31 examples, 31 failures

Failed examples:

rspec /tmp/d20160107-5693-17v3ks6/spec.rb:3 # LazyMode LazyMode::Date can parse year
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:8 # LazyMode LazyMode::Date can parse month
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:13 # LazyMode LazyMode::Date can parse day
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:20 # LazyMode LazyMode::Note has file_name
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:29 # LazyMode LazyMode::Note has header
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:98 # LazyMode LazyMode::Note can have nested notes
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:39 # LazyMode LazyMode::Note #tags has tags
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:48 # LazyMode LazyMode::Note #tags can have no tags
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:59 # LazyMode LazyMode::Note #status has status
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:68 # LazyMode LazyMode::Note #status can have default status
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:79 # LazyMode LazyMode::Note #body has body
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:88 # LazyMode LazyMode::Note #body can have no body
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:119 # LazyMode#daily_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:141 # LazyMode#daily_agenda returns note scheduled with daily repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:163 # LazyMode#daily_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:186 # LazyMode#daily_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:208 # LazyMode#daily_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:219 # LazyMode#daily_agenda returns nested notes
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:237 # LazyMode#weekly_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:259 # LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:283 # LazyMode#weekly_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:315 # LazyMode#weekly_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:337 # LazyMode#weekly_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:348 # LazyMode#weekly_agenda returns nested notes
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:390 # LazyMode#where filters by tag
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:408 # LazyMode#where filters by body text
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:420 # LazyMode#where filters by header text
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:432 # LazyMode#where filters by status
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:443 # LazyMode#where filters by multiple filters
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:456 # LazyMode.create_file can assign name to files
rspec /tmp/d20160107-5693-17v3ks6/spec.rb:463 # LazyMode.create_file can build notes in the block

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

Малина обнови решението на 21.12.2015 15:50 (преди около 9 години)

+module LazyMode
+
+class Date
+attr_reader :date
+
+def initialize(date)
+ @date = date
+end
+
+def self.year
+ year = @date.split('-')[0][-2,2]
+ if(year.length < 4)
+ year.insert(0,'0')
+ end
+ push year
+end
+
+def self.month
+ month = @date.split('-')[1]
+
+ if(month.length < 2)
+ month.insert(0,'0')
+ end
+ push month
+end
+
+def self.day
+ day = @date.split('-')[2]
+
+ if(day.length < 2)
+ day.insert(0,'0')
+ end
+ push day
+end
+
+def self.to_s
+ "#{year}-#{month}-#{day}"
+end
+
+end
+
+class Note < Struct.new(:header, :body, :status, :tags)
+ def self.new_note(header, body, status, tags)
+ Note.new(header.strip.downcase.to_sym,
+ body.strip,
+ status.strip.downcase.to_sym,
+ tags.split(',').map(&:strip))
+ end
+end
+
+class File
+
+ def initialize(name, notes = [])
+ @notes = notes
+ @name = name
+ end
+
+ def each(&block)
+ @notes.each &block
+ end
+
+ def self.create_file(name, notes = Note.new_note)
+ @notes[name] = notes
+ end
+
+ def self.name
+ file_name = "#{@name}"
+ end
+
+ def self.note
+ header = "#{@notes.header}"
+ tags = "#{@notes.tags}".join(" , ")
+ status = "#{@notes.status}"
+ body = "#{@notes.body}"
+ size = @notes.size
+ end
+
+ def self.scheduled(some_date)
+ current_date = LazyMode::Date.new(some_date)
+ scheduled_date = current_date
+
+ case occurence
+ when 'm' then end_date = current_date.month + 1
+ when 'd' then end_date = current_date.day + 1
+ when 'w' then end_date = current_date.day + 7
+ end
+ end
+
+ def serialize
+ file = "#{@notes.size}:#{serialize_entities(@name)}"
+
+ "#{file}"
+ end
+
+ protected
+ attr_reader :notes, :name
+end
+
+end

Малина обнови решението на 21.12.2015 16:41 (преди около 9 години)

module LazyMode
class Date
attr_reader :date
def initialize(date)
@date = date
end
def self.year
- year = @date.split('-')[0][-2,2]
- if(year.length < 4)
- year.insert(0,'0')
+ current_year = @date.to_s.split('-').first
+ if(current_year.to_i < 1000)
+ current_year.to_s.insert(0,'0')
end
- push year
+ current_year
end
def self.month
- month = @date.split('-')[1]
+ current_month = @date.to_s.split('-')[1]
- if(month.length < 2)
- month.insert(0,'0')
+ if(current_month.to_i < 10)
+ current_month.to_s.insert(0,'0')
end
- push month
+ current_month
end
def self.day
- day = @date.split('-')[2]
+ current_day = @date.to_s.split('-').last
- if(day.length < 2)
- day.insert(0,'0')
+ if(current_day.to_i < 10)
+ current_day.to_s.insert(0,'0')
end
- push day
+ current_day
end
def self.to_s
"#{year}-#{month}-#{day}"
end
end
class Note < Struct.new(:header, :body, :status, :tags)
def self.new_note(header, body, status, tags)
Note.new(header.strip.downcase.to_sym,
body.strip,
status.strip.downcase.to_sym,
tags.split(',').map(&:strip))
end
end
class File
def initialize(name, notes = [])
@notes = notes
@name = name
end
def each(&block)
@notes.each &block
end
def self.create_file(name, notes = Note.new_note)
@notes[name] = notes
end
def self.name
file_name = "#{@name}"
end
def self.note
header = "#{@notes.header}"
tags = "#{@notes.tags}".join(" , ")
status = "#{@notes.status}"
body = "#{@notes.body}"
size = @notes.size
end
def self.scheduled(some_date)
current_date = LazyMode::Date.new(some_date)
scheduled_date = current_date
case occurence
when 'm' then end_date = current_date.month + 1
when 'd' then end_date = current_date.day + 1
when 'w' then end_date = current_date.day + 7
end
end
def serialize
file = "#{@notes.size}:#{serialize_entities(@name)}"
"#{file}"
end
protected
attr_reader :notes, :name
end
end

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

module LazyMode
class Date
attr_reader :date
def initialize(date)
@date = date
end
-def self.year
+def year
current_year = @date.to_s.split('-').first
if(current_year.to_i < 1000)
current_year.to_s.insert(0,'0')
end
current_year
end
-def self.month
+def month
current_month = @date.to_s.split('-')[1]
if(current_month.to_i < 10)
current_month.to_s.insert(0,'0')
end
current_month
end
-def self.day
+def day
current_day = @date.to_s.split('-').last
if(current_day.to_i < 10)
current_day.to_s.insert(0,'0')
end
current_day
end
-def self.to_s
+def to_s
"#{year}-#{month}-#{day}"
end
end
class Note < Struct.new(:header, :body, :status, :tags)
def self.new_note(header, body, status, tags)
Note.new(header.strip.downcase.to_sym,
body.strip,
status.strip.downcase.to_sym,
tags.split(',').map(&:strip))
end
end
class File
def initialize(name, notes = [])
@notes = notes
@name = name
end
def each(&block)
@notes.each &block
end
- def self.create_file(name, notes = Note.new_note)
+ def self.create_file(name = File.new.name)
@notes[name] = notes
end
def self.name
file_name = "#{@name}"
end
- def self.note
+ def note
+ notes = Note.new_note
header = "#{@notes.header}"
tags = "#{@notes.tags}".join(" , ")
status = "#{@notes.status}"
body = "#{@notes.body}"
size = @notes.size
end
- def self.scheduled(some_date)
+ def scheduled(some_date)
current_date = LazyMode::Date.new(some_date)
scheduled_date = current_date
case occurence
when 'm' then end_date = current_date.month + 1
when 'd' then end_date = current_date.day + 1
when 'w' then end_date = current_date.day + 7
end
end
def serialize
file = "#{@notes.size}:#{serialize_entities(@name)}"
"#{file}"
end
protected
attr_reader :notes, :name
end
+
+ def self.create_file(name = File.new.name)
+ end
end