Решение на Четвърта задача от Дамян Димитров

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

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

Резултати

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

Код

module UI
class TextScreen
def self.draw(&block)
eval("define_method :label do | **kargs |
return @result += kargs[:text].send(kargs[:style]) if kargs[:style]
@result += kargs[:text]
end")
text_screen = new
text_screen.instance_eval { @result = ''}
text_screen.instance_eval &block
end
def horizontal(**kargs, &block)
eval("TextScreen.class_eval do
def label(**kargs)
return @result += kargs[:text].send(:downcase) if kargs[:style]
@result += kargs[:text]
end
end")
block.call
@result += "\n"
end
def vertical(**kargs, &block)
eval("TextScreen.class_eval do
def label(**kargs)
return @result += kargs[:text].send(:downcase) if kargs[:style]
@result += kargs[:text]
@result += \"\n\"
end
end")
block.call
end
end
end

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

...FFF.F.F.

Failures:

  1) Command Line Toolkit handles complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xb93d318c@/tmp/d20141126-26053-1gyww5j/spec.rb:56> to render as "      123\n        45\n         6\n      7\n"
     # /tmp/d20141126-26053-1gyww5j/spec.rb:56:in `block (2 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) Command Line Toolkit wraps vertically-aligned components correctly in border
     Failure/Error: expect do
       expected #<Proc:0xb93b8904@/tmp/d20141126-26053-1gyww5j/spec.rb:85> to render as "      |something|\n      |some     |\n      |soommee  |\n"
     # /tmp/d20141126-26053-1gyww5j/spec.rb:85:in `block (2 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) Command Line Toolkit handles borders correctly in complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xb93b0ccc@/tmp/d20141126-26053-1gyww5j/spec.rb:99> to render as "      |||1||2|||3|       |||\n      ||      |||4|||5||||||\n      ||      ||   ||6||||||\n      ||7|                 |\n"
     # /tmp/d20141126-26053-1gyww5j/spec.rb:99:in `block (2 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) Command Line Toolkit propagates upcase to child components
     Failure/Error: expect do
       expected #<Proc:0xb9390ae4@/tmp/d20141126-26053-1gyww5j/spec.rb:137> to render as "      someveryINTERESTINGget it?\n              TEXTGOES       \n                  HERE       \n"
     # /tmp/d20141126-26053-1gyww5j/spec.rb:137:in `block (2 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) Command Line Toolkit propagates downcase to child components
     Failure/Error: expect do
       expected #<Proc:0xb920fcec@/tmp/d20141126-26053-1gyww5j/spec.rb:172> to render as "      SOMEVERYinterestingGET IT?\n              textgoes       \n                  here       \n"
     # /tmp/d20141126-26053-1gyww5j/spec.rb:172:in `block (2 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.028 seconds
11 examples, 5 failures

Failed examples:

rspec /tmp/d20141126-26053-1gyww5j/spec.rb:55 # Command Line Toolkit handles complex group nestings
rspec /tmp/d20141126-26053-1gyww5j/spec.rb:84 # Command Line Toolkit wraps vertically-aligned components correctly in border
rspec /tmp/d20141126-26053-1gyww5j/spec.rb:98 # Command Line Toolkit handles borders correctly in complex group nestings
rspec /tmp/d20141126-26053-1gyww5j/spec.rb:136 # Command Line Toolkit propagates upcase to child components
rspec /tmp/d20141126-26053-1gyww5j/spec.rb:171 # Command Line Toolkit propagates downcase to child components

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

Дамян обнови решението на 26.11.2014 16:29 (преди почти 10 години)

+module UI
+ class TextScreen
+ def self.draw(&block)
+ eval("define_method :label do | **kargs |
+ return @result += kargs[:text].send(kargs[:style]) if kargs[:style]
+ @result += kargs[:text]
+ end")
+
+ text_screen = new
+ text_screen.instance_eval { @result = ''}
+ text_screen.instance_eval &block
+ end
+
+ def horizontal(**kargs, &block)
+ eval("TextScreen.class_eval do
+ def label(**kargs)
+ return @result += kargs[:text].send(:downcase) if kargs[:style]
+ @result += kargs[:text]
+ end
+ end")
+
+ block.call
+ @result += "\n"
+ end
+
+ def vertical(**kargs, &block)
+ eval("TextScreen.class_eval do
+ def label(**kargs)
+ return @result += kargs[:text].send(:downcase) if kargs[:style]
+ @result += kargs[:text]
+ @result += \"\n\"
+ end
+ end")
+
+ block.call
+ end
+ end
+end

Определено досега тази задача ме затрудни най-много. Предавам най-мръсния код, които съм писал някога. Сигурно ще мина някакви тестове, но едва ли заслужавам и точка за това си творение. Чакам с нетърпение да видя коректни решения :)