Class: Bread::Basket::Poster::BoxChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/bread/basket/poster/box_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(box, dimensions) ⇒ BoxChecker

Returns a new instance of BoxChecker.



11
12
13
14
# File 'lib/bread/basket/poster/box_checker.rb', line 11

def initialize(box, dimensions)
  @box = box
  @dimensions = dimensions
end

Instance Attribute Details

#boxObject (readonly)

Determines which dimensions were provided and if provided dimensions are sufficient to determine left, right, top, and width of box bottom and height are optional but if top is missing are required to determine location of top.



9
10
11
# File 'lib/bread/basket/poster/box_checker.rb', line 9

def box
  @box
end

#dimensionsObject (readonly)

Determines which dimensions were provided and if provided dimensions are sufficient to determine left, right, top, and width of box bottom and height are optional but if top is missing are required to determine location of top.



9
10
11
# File 'lib/bread/basket/poster/box_checker.rb', line 9

def dimensions
  @dimensions
end

Instance Method Details

#box_ok?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bread/basket/poster/box_checker.rb', line 44

def box_ok?
  horizontal_ok? && vertical_ok?
end

#horizontal_dimensionsObject



16
17
18
19
20
21
22
23
# File 'lib/bread/basket/poster/box_checker.rb', line 16

def horizontal_dimensions
  arr = []
  dimensions.each_key do |key|
    arr << key if  %w(left right width).include? key
  end
  warn_right if arr.length > 2
  arr
end

#horizontal_ok?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/bread/basket/poster/box_checker.rb', line 34

def horizontal_ok?
  horiz = %w(left right width) - horizontal_dimensions
  horiz.length < 2
end

#vertical_dimensionsObject



25
26
27
28
29
30
31
32
# File 'lib/bread/basket/poster/box_checker.rb', line 25

def vertical_dimensions
  arr = []
  dimensions.each_key do |key|
    arr << key if  %w(top bottom height).include? key
  end
  warn_bottom if arr.length > 2
  arr
end

#vertical_ok?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/bread/basket/poster/box_checker.rb', line 39

def vertical_ok?
  bottom_and_height = %w(bottom height).all? { |s| dimensions.key? s }
  dimensions.key?('top') || bottom_and_height
end

#warn_bottomObject



53
54
55
56
# File 'lib/bread/basket/poster/box_checker.rb', line 53

def warn_bottom
  puts "Warning: For selector #{box.selector_name}, top, height AND bottom were " \
        'provided. Bottom will be ignored.'
end

#warn_rightObject



48
49
50
51
# File 'lib/bread/basket/poster/box_checker.rb', line 48

def warn_right
  puts "Warning: For selector #{box.selector_name}, left, width AND right were " \
        'provided. Right will be ignored.'
end