Class: Bread::Basket::Poster::BoxChecker
- Inherits:
-
Object
- Object
- Bread::Basket::Poster::BoxChecker
- Defined in:
- lib/bread/basket/poster/box_checker.rb
Instance Attribute Summary collapse
-
#box ⇒ Object
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.
-
#dimensions ⇒ Object
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.
Instance Method Summary collapse
- #box_ok? ⇒ Boolean
- #horizontal_dimensions ⇒ Object
- #horizontal_ok? ⇒ Boolean
-
#initialize(box, dimensions) ⇒ BoxChecker
constructor
A new instance of BoxChecker.
- #vertical_dimensions ⇒ Object
- #vertical_ok? ⇒ Boolean
- #warn_bottom ⇒ Object
- #warn_right ⇒ Object
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
#box ⇒ Object (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 |
#dimensions ⇒ Object (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
44 45 46 |
# File 'lib/bread/basket/poster/box_checker.rb', line 44 def box_ok? horizontal_ok? && vertical_ok? end |
#horizontal_dimensions ⇒ Object
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
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_dimensions ⇒ Object
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
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_bottom ⇒ Object
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_right ⇒ Object
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 |