Решение на Пета задача от Теодор Николов

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

Към профила на Теодор Николов

Резултати

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

Код

class FormatParagraph
def initialize(text)
@text = text
end
def to_html
@text.gsub(/^[^#>](.*)\n/, '<p>\1</p>'"\n")
end
end
class FormatCode
def initialize(text)
@text = text
end
def to_html
html = @text.gsub(/^[ ]{4}(.*)\n[^( )]/m, '<pre><code>\1</code></pre>')
end
end
class Formater
def initialize(text)
@text = text
end
def to_html
@text = FormatCode.new(@text).to_html
#@text = FormatParagraph.new(@text).to_html
@text
end
def inspect
@text
end
end

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

/tmp/d20111129-16859-139bi3y/spec.rb:3:in `<top (required)>': uninitialized constant Object::Formatter (NameError)
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `block in load_spec_files'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `map'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:in `run'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_in_process'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
	from /data/rails/evans/releases/20111128224832/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'

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

Теодор обнови решението на 22.11.2011 23:51 (преди над 12 години)

+class FormatParagraph
+ def initialize(text)
+ @text = text
+ end
+
+ def to_html
+ @text.gsub(/^[^#>](.*)\n/, '<p>\1</p>'"\n")
+ end
+end
+
+class FormatCode
+ def initialize(text)
+ @text = text
+ end
+
+ def to_html
+ html = @text.gsub(/^[ ]{4}(.*)\n[^( )]/m, '<pre><code>\1</code></pre>')
+ end
+end
+
+class Formater
+ def initialize(text)
+ @text = text
+ end
+
+ def to_html
+ @text = FormatCode.new(@text).to_html
+ #@text = FormatParagraph.new(@text).to_html
+ @text
+ end
+
+ def inspect
+ @text
+ end
+end

Идентираш с табове. Конвенцията е два интервала за идентация. Моля те, оправи си го, защото след крайния срок ще ти се вземат точки за това, понеже сме го казвали 422 пъти вече.

П. П. Виждам, че май не си пускал примерните тестове още. (Класът ти се казва неправилно Formater (правилното е с две t). Предвид оставащото време до крайния срок, те съветвам да започнеш с имплементация на параграфите и след това да оправяш нещата, които гърмят във всеки примерен тест.