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

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

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

Резултати

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

Код

module UI
class TextScreen
def self.draw(&block)
text_designer = Features.new
text_designer.instance_eval &block
text_designer.composed_text
end
end
class Features
attr_reader :composed_text
def initialize
@composed_text = ""
end
def label(text: "", border: nil, style: nil)
@composed_text << "#{border}#{text_style(text, style)}#{border}"
if @new_line then @composed_text << "\n" end
end
def vertical(border: nil, style: nil, &block)
@temp = @new_line
@new_line = true
block.call
if not @temp then @composed_text.chomp! end
@new_line = @temp
end
def horizontal(border: nil, style: nil, &block)
@temp, @new_line = @new_line, false
@composed_text << border
block.call
@composed_text << border
if @temp then @composed_text << "\n" end
@new_line = @temp
end
def text_style(text, style)
if style
text.public_send style
else
text
end
end
end
end

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

.F.FFF.F.F.

Failures:

  1) Command Line Toolkit adding horizontal group does not change the behavior
     Failure/Error: horizontal do
     TypeError:
       no implicit conversion of nil into String
     # /tmp/d20141126-26053-61mcrg/solution.rb:32:in `horizontal'
     # /tmp/d20141126-26053-61mcrg/spec.rb:31:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `instance_eval'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `draw'
     # /tmp/d20141126-26053-61mcrg/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/spec.rb:30: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 handles complex group nestings
     Failure/Error: horizontal do
     TypeError:
       no implicit conversion of nil into String
     # /tmp/d20141126-26053-61mcrg/solution.rb:32:in `horizontal'
     # /tmp/d20141126-26053-61mcrg/spec.rb:58:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/solution.rb:25:in `call'
     # /tmp/d20141126-26053-61mcrg/solution.rb:25:in `vertical'
     # /tmp/d20141126-26053-61mcrg/spec.rb:57:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `instance_eval'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `draw'
     # /tmp/d20141126-26053-61mcrg/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/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)>'

  3) Command Line Toolkit wraps vertically-aligned components correctly in border
     Failure/Error: expect do
       expected #<Proc:0xb8e773c8@/tmp/d20141126-26053-61mcrg/spec.rb:85> to render as "      |something|\n      |some     |\n      |soommee  |\n"
     # /tmp/d20141126-26053-61mcrg/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)>'

  4) Command Line Toolkit handles borders correctly in complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xb8e74560@/tmp/d20141126-26053-61mcrg/spec.rb:99> to render as "      |||1||2|||3|       |||\n      ||      |||4|||5||||||\n      ||      ||   ||6||||||\n      ||7|                 |\n"
     # /tmp/d20141126-26053-61mcrg/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)>'

  5) Command Line Toolkit propagates upcase to child components
     Failure/Error: horizontal do
     TypeError:
       no implicit conversion of nil into String
     # /tmp/d20141126-26053-61mcrg/solution.rb:32:in `horizontal'
     # /tmp/d20141126-26053-61mcrg/spec.rb:138:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `instance_eval'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `draw'
     # /tmp/d20141126-26053-61mcrg/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/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)>'

  6) Command Line Toolkit propagates downcase to child components
     Failure/Error: horizontal do
     TypeError:
       no implicit conversion of nil into String
     # /tmp/d20141126-26053-61mcrg/solution.rb:32:in `horizontal'
     # /tmp/d20141126-26053-61mcrg/spec.rb:173:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `instance_eval'
     # /tmp/d20141126-26053-61mcrg/solution.rb:5:in `draw'
     # /tmp/d20141126-26053-61mcrg/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-61mcrg/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.02046 seconds
11 examples, 6 failures

Failed examples:

rspec /tmp/d20141126-26053-61mcrg/spec.rb:29 # Command Line Toolkit adding horizontal group does not change the behavior
rspec /tmp/d20141126-26053-61mcrg/spec.rb:55 # Command Line Toolkit handles complex group nestings
rspec /tmp/d20141126-26053-61mcrg/spec.rb:84 # Command Line Toolkit wraps vertically-aligned components correctly in border
rspec /tmp/d20141126-26053-61mcrg/spec.rb:98 # Command Line Toolkit handles borders correctly in complex group nestings
rspec /tmp/d20141126-26053-61mcrg/spec.rb:136 # Command Line Toolkit propagates upcase to child components
rspec /tmp/d20141126-26053-61mcrg/spec.rb:171 # Command Line Toolkit propagates downcase to child components

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

Методи обнови решението на 26.11.2014 16:05 (преди над 9 години)

+module UI
+ class TextScreen
+ def self.draw(&block)
+ text_designer = Features.new
+ text_designer.instance_eval &block
+ text_designer.composed_text
+ end
+ end
+
+ class Features
+ attr_reader :composed_text
+
+ def initialize
+ @composed_text = ""
+ end
+
+ def label(text: "", border: nil, style: nil)
+ @composed_text << "#{border}#{text_style(text, style)}#{border}"
+ if @new_line then @composed_text << "\n" end
+ end
+
+ def vertical(border: "", &block)
+ @temp = @new_line
+ @new_line = true
+ block.call
+ if not @temp then @composed_text.chomp! end
+ @new_line = @temp
+ end
+
+ def horizontal(border: nil, style: nil, &block)
+ @temp, @new_line = @new_line, false
+ @composed_text << border
+ block.call
+ @composed_text << border
+ if @temp then @composed_text << "\n" end
+ @new_line = @temp
+ end
+
+ def text_style(text, style)
+ if style
+ text.public_send style
+ else
+ text
+ end
+ end
+ end
+end

Методи обнови решението на 26.11.2014 16:12 (преди над 9 години)

module UI
class TextScreen
def self.draw(&block)
text_designer = Features.new
text_designer.instance_eval &block
text_designer.composed_text
end
end
class Features
attr_reader :composed_text
def initialize
@composed_text = ""
end
def label(text: "", border: nil, style: nil)
@composed_text << "#{border}#{text_style(text, style)}#{border}"
if @new_line then @composed_text << "\n" end
end
- def vertical(border: "", &block)
+ def vertical(border: nil, style: nil, &block)
@temp = @new_line
@new_line = true
block.call
if not @temp then @composed_text.chomp! end
@new_line = @temp
end
def horizontal(border: nil, style: nil, &block)
@temp, @new_line = @new_line, false
@composed_text << border
block.call
@composed_text << border
if @temp then @composed_text << "\n" end
@new_line = @temp
end
def text_style(text, style)
if style
text.public_send style
else
text
end
end
end
end