Решение на Четвърта задача от Габриела Лухова

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

Към профила на Габриела Лухова

Резултати

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

Код

module UI
class TextScreen
def self.draw(&block)
Proxy.new.instance_eval(&block)
end
end
class Proxy
attr_accessor :message, :arr
def initialize
@message = ""
@arr = []
end
def label(text:, border: nil, style: nil)
@message = "#{text}"
@message = "#{text}".upcase if "#{style}" == "upcase"
@message = "#{text}".downcase if "#{style}" == "downcase"
@message = "#{border}" + @message + "#{border}" if border
@arr << @message
@arr.join
end
def vertical(style: nil, border: nil, &block)
block.call(self)
@arr.join("\n")
end
end
end

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

.F.FFF.F.F.

Failures:

  1) Command Line Toolkit adding horizontal group does not change the behavior
     Failure/Error: horizontal do
     NoMethodError:
       undefined method `horizontal' for #<UI::Proxy:0xba086c58 @message="", @arr=[]>
     # /tmp/d20141126-26053-2uhwb9/spec.rb:31:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `instance_eval'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `draw'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/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
     NoMethodError:
       undefined method `horizontal' for #<UI::Proxy:0xba084200 @message="", @arr=[]>
     # /tmp/d20141126-26053-2uhwb9/spec.rb:58:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:24:in `call'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:24:in `vertical'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:57:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `instance_eval'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `draw'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/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:0xba083594@/tmp/d20141126-26053-2uhwb9/spec.rb:85> to render as "      |something|\n      |some     |\n      |soommee  |\n"
     # /tmp/d20141126-26053-2uhwb9/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: horizontal border: '|' do
     NoMethodError:
       undefined method `horizontal' for #<UI::Proxy:0xba07bfd8 @message="", @arr=[]>
     # /tmp/d20141126-26053-2uhwb9/spec.rb:101:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:24:in `call'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:24:in `vertical'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:100:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `instance_eval'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `draw'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/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
     NoMethodError:
       undefined method `horizontal' for #<UI::Proxy:0xba0640a4 @message="", @arr=[]>
     # /tmp/d20141126-26053-2uhwb9/spec.rb:138:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `instance_eval'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `draw'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/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
     NoMethodError:
       undefined method `horizontal' for #<UI::Proxy:0xba05cffc @message="", @arr=[]>
     # /tmp/d20141126-26053-2uhwb9/spec.rb:173:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `instance_eval'
     # /tmp/d20141126-26053-2uhwb9/solution.rb:4:in `draw'
     # /tmp/d20141126-26053-2uhwb9/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-2uhwb9/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.01951 seconds
11 examples, 6 failures

Failed examples:

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

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

Габриела обнови решението на 26.11.2014 13:39 (преди над 9 години)

+module UI
+ class TextScreen
+ def self.draw(&block)
+ Proxy.new.instance_eval(&block)
+ end
+ end
+
+ class Proxy
+ attr_accessor :message, :arr
+ def initialize
+ @message = ""
+ @arr = []
+ end
+ def label(text:, border: nil, style: nil)
+ @message = "#{text}"
+ @message = "#{text}".upcase if "#{style}" == "upcase"
+ @message = "#{text}".downcase if "#{style}" == "downcase"
+ @message = "#{border}" + @message + "#{border}" if border
+ @arr << @message
+ @arr.join
+ end
+
+ def vertical(style: nil, border: nil, &block)
+ block.call(self)
+ @arr.join("\n")
+ end
+ end
+end