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

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

Към профила на Людмил Делчев

Резултати

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

Код

module UI
class TextScreen
@screen = ""
@labels_separator = ""
def TextScreen.format_text(text, style: nil, border: nil)
text = "#{border}#{text}#{border}" unless border == nil
text = text.upcase if style == :upcase
text = text.downcase if style == :downcase
text
end
def TextScreen.label(text:, style: nil, border: nil)
text = format_text(text, style: style, border: border)
if @screen == ""
@screen = @screen << text
else
@screen = @screen << @labels_separator << text
end
end
def TextScreen.vertical(&block)
@labels_separator = "\n"
block.call
@labels_separator = ""
end
def TextScreen.horizontal(&block)
block.call
end
def TextScreen.draw(&block)
@screen = ""
instance_eval &block
@screen
end
end
end

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

...FFF.F.F.

Failures:

  1) Command Line Toolkit handles complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xb9f586c4@/tmp/d20141126-26053-1jdwq0i/spec.rb:56> to render as "      123\n        45\n         6\n      7\n"
     # /tmp/d20141126-26053-1jdwq0i/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: vertical border: '|' do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:23:in `vertical'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:86:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `instance_eval'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `draw'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/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: vertical border: '|' do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:23:in `vertical'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:100:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `instance_eval'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `draw'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/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: vertical style: :upcase do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:23:in `vertical'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:142:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:30:in `call'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:30:in `horizontal'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:138:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `instance_eval'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `draw'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/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: vertical style: :downcase do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:23:in `vertical'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:177:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:30:in `call'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:30:in `horizontal'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:173:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `instance_eval'
     # /tmp/d20141126-26053-1jdwq0i/solution.rb:35:in `draw'
     # /tmp/d20141126-26053-1jdwq0i/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1jdwq0i/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.02009 seconds
11 examples, 5 failures

Failed examples:

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

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

Людмил обнови решението на 26.11.2014 14:11 (преди над 9 години)

+module UI
+
+ class TextScreen
+ @screen = ""
+ @labels_separator = ""
+
+ def TextScreen.format_text(text, style: nil, border: nil)
+ text = "#{border}#{text}#{border}" unless border == nil
+ text = text.upcase if style == :upcase
+ text = text.downcase if style == :downcase
+ text
+ end
+
+ def TextScreen.label(text:, style: nil, border: nil)
+ text = format_text(text, style: style, border: border)
+ if @screen == ""
+ @screen = @screen << text
+ else
+ @screen = @screen << @labels_separator << text
+ end
+ end
+
+ def TextScreen.vertical(&block)
+ @labels_separator = "\n"
+ block.call
+ @labels_separator = ""
+ end
+
+ def TextScreen.horizontal(&block)
+ block.call
+ end
+
+ def TextScreen.draw(&block)
+ @screen = ""
+ instance_eval &block
+ @screen
+ end
+ end
+end