Решение на Втора задача от Константин Димитров

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

Към профила на Константин Димитров

Резултати

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

Код

include Enumerable
class ToDoTask
def initialize(status, description, priority, tags)
@status = status
@description = description
@priority = priority
@tags = tags
def each
yield @status
yield @description
yield @priority
yield @tags
end
end
def status()
@status.downcase.to_sym
end
def description()
@description
end
def priority()
@priority.downcase.to_sym
end
def tags()
@tags.split(', ')
end
end
class ToDoList
def self.parse(text)
list_of_rows = text.split("\n")
list_of_tasks = list_of_rows.map{|n| n.strip.split('|')}
@todo_list = list_of_tasks.map{|n| ToDoTask.new(n[0], n[1], n[2], n[3]) }
end
def self.filter(criteria)
@todo_list.select{ |task| task[criteria[0]] == criteria[1]}
end
def tasks_todo()
@todo_list.count{|task| task[0]=="TODO"}
end
def tasks_in_progress()
@todo_list.count{|task| task[0]=="CURRENT"}
end
def tasks_completed()
@todo_list.count{|task| task[0]=="DONE"}
end
end
class Criteria
def self.status(arg)
[0, arg.to_s.upcase]
end
def self.priority(arg)
[2, arg.to_s.capitalize]
end
def self.tags(arg)
[3, arg]
end
end

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

/tmp/d20131107-4393-ice6sr/spec.rb:1:in `<top (required)>': uninitialized constant TodoList (NameError)
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:in `run'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

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

Константин обнови решението на 06.11.2013 13:52 (преди около 11 години)

+include Enumerable
+class ToDoTask
+ def initialize(status, description, priority, tags)
+ @status = status
+ @description = description
+ @priority = priority
+ @tags = tags
+
+ def each
+ yield @status
+ yield @description
+ yield @priority
+ yield @tags
+ end
+ end
+
+ def status()
+ @status.downcase.to_sym
+ end
+
+ def description()
+ @description
+ end
+
+ def priority()
+ @priority.downcase.to_sym
+ end
+
+ def tags()
+ @tags.split(', ')
+ end
+end
+
+class ToDoList
+ def self.parse(text)
+ list_of_rows = text.split("\n")
+ list_of_tasks = list_of_rows.map{|n| n.strip.split('|')}
+ @todo_list = list_of_tasks.map{|n| ToDoTask.new(n[0], n[1], n[2], n[3]) }
+ end
+
+ def self.filter(criteria)
+ @todo_list.select{ |task| task[criteria[0]] == criteria[1]}
+ end
+
+ def tasks_todo()
+ @todo_list.count{|task| task[0]=="TODO"}
+ end
+
+ def tasks_in_progress()
+ @todo_list.count{|task| task[0]=="CURRENT"}
+ end
+
+ def tasks_completed()
+ @todo_list.count{|task| task[0]=="DONE"}
+ end
+end
+
+class Criteria
+ def self.status(arg)
+ [0, arg.to_s.upcase]
+ end
+
+ def self.priority(arg)
+ [2, arg.to_s.capitalize]
+ end
+
+ def self.tags(arg)
+ [3, arg]
+ end
+end