Решение на Четвърта задача от Снежана Спасова

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

Към профила на Снежана Спасова

Резултати

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

Код

module UI
class Style
def initialize
@labels = []
@horizontal = []
end
def form(text, border)
border + text + border
end
def style(text, style)
style.length != 0 ? text.send(style) : text
end
def label(arguments_to_style)
@style, @border = arguments_to_style[:style], arguments_to_style[:border]
@labels << style(arguments_to_style[:text], @style.to_s)
@labels.map { |word| form(word, @border.to_s) }
end
def vertical(text, options)
@border, @style = options[:border].to_s, options[:style].to_s
max = text.max_by(&:length).length
text.map { |ch| form(style(ch.ljust(max), @style), @border) + "\n" }.join
end
def horizontal(text, options)
@border, @style, @labels = options[:border], options[:style], []
horizontal = []
text.each do |word|
horizontal << style(word, @style.to_s)
end
@horizontal << form(horizontal.join, @border.to_s)
end
end
class TextScreen
def self.draw(&block)
@blocks_count = 1
@style = Style.new()
instance_eval(&block)
end
def self.label(label)
@blocks_count == 1 ? @style.label(label).join : @style.label(label)
end
def self.vertical(options = {}, &block)
@blocks_count += 1
@style.vertical(instance_eval(&block), options)
end
def self.horizontal(options = {}, &block)
@blocks_count += 1
@style.horizontal(instance_exec(&block), options)
end
end
end

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

.F.F.F.F.F.

Failures:

  1) Command Line Toolkit adding horizontal group does not change the behavior
     Failure/Error: expect do
       expected #<Proc:0xb9e025a4@/tmp/d20141126-26053-1hcij36/spec.rb:30> to render as "      123\n"
     # /tmp/d20141126-26053-1hcij36/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 `each' for "1\n2\n3\n4\n5\n6\n":String
     # /tmp/d20141126-26053-1hcij36/solution.rb:31:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:64:in `block (6 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `vertical'
     # /tmp/d20141126-26053-1hcij36/spec.rb:62:in `block (5 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `instance_exec'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:58:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `vertical'
     # /tmp/d20141126-26053-1hcij36/spec.rb:57:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `draw'
     # /tmp/d20141126-26053-1hcij36/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/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 handles borders correctly in complex group nestings
     Failure/Error: horizontal border: '|' do
     NoMethodError:
       undefined method `each' for "||1||\n||2||\n||3||\n||4||\n||5||\n||6||\n":String
     # /tmp/d20141126-26053-1hcij36/solution.rb:31:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:107:in `block (6 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `vertical'
     # /tmp/d20141126-26053-1hcij36/spec.rb:105:in `block (5 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `instance_exec'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:101:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `vertical'
     # /tmp/d20141126-26053-1hcij36/spec.rb:100:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `draw'
     # /tmp/d20141126-26053-1hcij36/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/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: horizontal do
     NoMethodError:
       undefined method `each' for #<String:0xb9dd8c18>
     # /tmp/d20141126-26053-1hcij36/solution.rb:31:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:144:in `block (5 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `vertical'
     # /tmp/d20141126-26053-1hcij36/spec.rb:142:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `instance_exec'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:138:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `draw'
     # /tmp/d20141126-26053-1hcij36/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/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: horizontal do
     NoMethodError:
       undefined method `each' for #<String:0xb9dccfa8>
     # /tmp/d20141126-26053-1hcij36/solution.rb:31:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:179:in `block (5 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:51:in `vertical'
     # /tmp/d20141126-26053-1hcij36/spec.rb:177:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `instance_exec'
     # /tmp/d20141126-26053-1hcij36/solution.rb:56:in `horizontal'
     # /tmp/d20141126-26053-1hcij36/spec.rb:173:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `instance_eval'
     # /tmp/d20141126-26053-1hcij36/solution.rb:42:in `draw'
     # /tmp/d20141126-26053-1hcij36/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-1hcij36/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.01981 seconds
11 examples, 5 failures

Failed examples:

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

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

Снежана обнови решението на 26.11.2014 03:23 (преди почти 10 години)

+module UI
+ class Style
+ def initialize
+ @labels = []
+ @horizontal = []
+ end
+
+ def form(text, border)
+ border + text + border
+ end
+ def style(text, style)
+ style.length != 0 ? text.send(style) : text
+ end
+
+ def label(arguments_to_style)
+ @style, @border = arguments_to_style[:style], arguments_to_style[:border]
+ @labels << style(arguments_to_style[:text], @style.to_s)
+ @labels.map { |word| form(word, @border.to_s) }
+ end
+
+ def vertical(text, options)
+ @border, @style = options[:border].to_s, options[:style].to_s
+ max = text.max_by(&:length).length
+ text.map { |ch| form(style(ch.ljust(max), @style), @border) + "\n" }.join
+ end
+
+ def horizontal(text, options)
+ @border, @style, @labels = options[:border], options[:style], []
+ horizontal = []
+ text.each do |word|
+ horizontal << style(word, @style.to_s)
+ end
+ @horizontal << form(horizontal.join, @border.to_s)
+ end
+ end
+ class TextScreen
+ def self.draw(&block)
+ @blocks_count = 1
+ @style = Style.new()
+ instance_eval(&block)
+ end
+
+ def self.label(label)
+ @blocks_count == 1 ? @styler.label(label).join : @styler.label(label)
+ end
+
+ def self.vertical(&block)
+ @blocks_count += 1
+ @style.vertical(instance_eval(&block))
+ end
+ def self.vertical(border = {}, &block)
+ @blocks_count += 1
+ @style.vertical(instance_eval(&block), border)
+ end
+
+ def self.horizontal(options = {}, &block)
+ @blocks_count += 1
+ @styler.horizontal(instance_exec(&block), options)
+ end
+ end
+end

Снежана обнови решението на 26.11.2014 03:24 (преди почти 10 години)

module UI
class Style
def initialize
@labels = []
@horizontal = []
end
def form(text, border)
border + text + border
end
+
def style(text, style)
style.length != 0 ? text.send(style) : text
end
def label(arguments_to_style)
@style, @border = arguments_to_style[:style], arguments_to_style[:border]
@labels << style(arguments_to_style[:text], @style.to_s)
@labels.map { |word| form(word, @border.to_s) }
end
def vertical(text, options)
@border, @style = options[:border].to_s, options[:style].to_s
max = text.max_by(&:length).length
text.map { |ch| form(style(ch.ljust(max), @style), @border) + "\n" }.join
end
def horizontal(text, options)
@border, @style, @labels = options[:border], options[:style], []
horizontal = []
text.each do |word|
horizontal << style(word, @style.to_s)
end
@horizontal << form(horizontal.join, @border.to_s)
end
end
+
class TextScreen
def self.draw(&block)
@blocks_count = 1
@style = Style.new()
instance_eval(&block)
end
def self.label(label)
@blocks_count == 1 ? @styler.label(label).join : @styler.label(label)
end
def self.vertical(&block)
@blocks_count += 1
@style.vertical(instance_eval(&block))
end
+
def self.vertical(border = {}, &block)
@blocks_count += 1
@style.vertical(instance_eval(&block), border)
end
def self.horizontal(options = {}, &block)
@blocks_count += 1
@styler.horizontal(instance_exec(&block), options)
end
end
end

Снежана обнови решението на 26.11.2014 03:26 (преди почти 10 години)

module UI
class Style
def initialize
@labels = []
@horizontal = []
end
def form(text, border)
border + text + border
end
def style(text, style)
style.length != 0 ? text.send(style) : text
end
def label(arguments_to_style)
@style, @border = arguments_to_style[:style], arguments_to_style[:border]
@labels << style(arguments_to_style[:text], @style.to_s)
@labels.map { |word| form(word, @border.to_s) }
end
def vertical(text, options)
@border, @style = options[:border].to_s, options[:style].to_s
max = text.max_by(&:length).length
text.map { |ch| form(style(ch.ljust(max), @style), @border) + "\n" }.join
end
def horizontal(text, options)
@border, @style, @labels = options[:border], options[:style], []
horizontal = []
text.each do |word|
horizontal << style(word, @style.to_s)
end
- @horizontal << form(horizontal.join, @border.to_s)
+ @horizontal << form(horizontal.join, @border.to_s)
end
end
class TextScreen
def self.draw(&block)
@blocks_count = 1
@style = Style.new()
instance_eval(&block)
end
def self.label(label)
- @blocks_count == 1 ? @styler.label(label).join : @styler.label(label)
+ @blocks_count == 1 ? @style.label(label).join : @style.label(label)
end
- def self.vertical(&block)
- @blocks_count += 1
- @style.vertical(instance_eval(&block))
- end
-
def self.vertical(border = {}, &block)
@blocks_count += 1
@style.vertical(instance_eval(&block), border)
end
def self.horizontal(options = {}, &block)
@blocks_count += 1
- @styler.horizontal(instance_exec(&block), options)
+ @style.horizontal(instance_exec(&block), options)
end
end
end

Снежана обнови решението на 26.11.2014 03:27 (преди почти 10 години)

module UI
class Style
def initialize
@labels = []
@horizontal = []
end
def form(text, border)
border + text + border
end
def style(text, style)
style.length != 0 ? text.send(style) : text
end
def label(arguments_to_style)
@style, @border = arguments_to_style[:style], arguments_to_style[:border]
@labels << style(arguments_to_style[:text], @style.to_s)
@labels.map { |word| form(word, @border.to_s) }
end
def vertical(text, options)
@border, @style = options[:border].to_s, options[:style].to_s
max = text.max_by(&:length).length
text.map { |ch| form(style(ch.ljust(max), @style), @border) + "\n" }.join
end
def horizontal(text, options)
@border, @style, @labels = options[:border], options[:style], []
horizontal = []
text.each do |word|
horizontal << style(word, @style.to_s)
end
@horizontal << form(horizontal.join, @border.to_s)
end
end
class TextScreen
def self.draw(&block)
@blocks_count = 1
@style = Style.new()
instance_eval(&block)
end
def self.label(label)
@blocks_count == 1 ? @style.label(label).join : @style.label(label)
end
- def self.vertical(border = {}, &block)
+ def self.vertical(options = {}, &block)
@blocks_count += 1
- @style.vertical(instance_eval(&block), border)
+ @style.vertical(instance_eval(&block), options)
end
def self.horizontal(options = {}, &block)
@blocks_count += 1
@style.horizontal(instance_exec(&block), options)
end
end
end