Class: Bread::Basket::Poster::Box
- Inherits:
-
Object
- Object
- Bread::Basket::Poster::Box
- Includes:
- UnitsHelper
- Defined in:
- lib/bread/basket/poster/box.rb
Direct Known Subclasses
Constant Summary
Constants included from UnitsHelper
UnitsHelper::DIMENSIONS, UnitsHelper::HASH_SELECTOR_REGEX, UnitsHelper::MEASUREMENT_REGEX, UnitsHelper::NUMERIC_REGEX
Instance Attribute Summary collapse
-
#bottom ⇒ Object
Returns the value of attribute bottom.
-
#content ⇒ Object
Returns the value of attribute content.
-
#height ⇒ Object
Returns the value of attribute height.
-
#layout ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#left ⇒ Object
Returns the value of attribute left.
-
#method_name ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#pending ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#right ⇒ Object
Returns the value of attribute right.
-
#selector_name ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#specs ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#stretchy ⇒ Object
Returns the value of attribute stretchy.
-
#styles ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#top ⇒ Object
Returns the value of attribute top.
-
#unfinished ⇒ Object
readonly
Box does most of the heavy lifting of the self-referential css so it’s a little confusing.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_to_determined(dimension_name, value) ⇒ Object
-
#determine_missing(missing_dimension) ⇒ Object
Rubocop hates determine_missing rubocop:disable all.
- #fetch_names(name) ⇒ Object
-
#initialize(name, layout, specs = {}) ⇒ Box
constructor
A new instance of Box.
-
#inspect ⇒ Object
rubocop:enable all.
- #ready_to_resolve?(hash) ⇒ Boolean
- #resolve_box ⇒ Object
- #resolve_dimension(dimension, hash) ⇒ Object
- #safe?(command_array) ⇒ Boolean
- #setup_dimensions ⇒ Object
- #stretchy? ⇒ Boolean
- #try_dimension(dimensions_hash) ⇒ Object
- #try_to_resolve ⇒ Object
Methods included from UnitsHelper
#convert_inner_units, #convert_units
Constructor Details
#initialize(name, layout, specs = {}) ⇒ Box
Returns a new instance of Box.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bread/basket/poster/box.rb', line 15 def initialize(name, layout, specs = {}) fetch_names(name) @layout = layout @specs = specs @styles = specs @pending = [] @unfinished = [] setup_dimensions layout.image_boxes << method_name if self.is_a? ImageBox layout.boxes << selector_name end |
Instance Attribute Details
#bottom ⇒ Object
Returns the value of attribute bottom.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def bottom @bottom end |
#content ⇒ Object
Returns the value of attribute content.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def content @content end |
#height ⇒ Object
Returns the value of attribute height.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def height @height end |
#layout ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def layout @layout end |
#left ⇒ Object
Returns the value of attribute left.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def left @left end |
#method_name ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def method_name @method_name end |
#pending ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def pending @pending end |
#right ⇒ Object
Returns the value of attribute right.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def right @right end |
#selector_name ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def selector_name @selector_name end |
#specs ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def specs @specs end |
#stretchy ⇒ Object
Returns the value of attribute stretchy.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def stretchy @stretchy end |
#styles ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def styles @styles end |
#top ⇒ Object
Returns the value of attribute top.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def top @top end |
#unfinished ⇒ Object (readonly)
Box does most of the heavy lifting of the self-referential css so it’s a little confusing. It passes dimensions off to the dimensions helper and holds the methods for setting dimensions as either pending or determined and how to resolve those issues.
10 11 12 |
# File 'lib/bread/basket/poster/box.rb', line 10 def unfinished @unfinished end |
#width ⇒ Object
Returns the value of attribute width.
12 13 14 |
# File 'lib/bread/basket/poster/box.rb', line 12 def width @width end |
Instance Method Details
#add_to_determined(dimension_name, value) ⇒ Object
75 76 77 78 79 |
# File 'lib/bread/basket/poster/box.rb', line 75 def add_to_determined(dimension_name, value) name = method_name + '.' + dimension_name instance_variable_set "@#{dimension_name}", value layout.determined[name] = value end |
#determine_missing(missing_dimension) ⇒ Object
Rubocop hates determine_missing rubocop:disable all
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/bread/basket/poster/box.rb', line 87 def determine_missing(missing_dimension) value = case missing_dimension when 'left' right - width when 'right' left + width when 'width' right - left when 'top' bottom + height when 'height' top - bottom when 'bottom' top - height end add_to_determined missing_dimension, value end |
#fetch_names(name) ⇒ Object
28 29 30 31 |
# File 'lib/bread/basket/poster/box.rb', line 28 def fetch_names(name) @selector_name = name @method_name = name.sub('.', '').gsub('-', '_') end |
#inspect ⇒ Object
rubocop:enable all
105 106 107 108 109 110 111 |
# File 'lib/bread/basket/poster/box.rb', line 105 def inspect str = '' %w(top left width height bottom right).each do |dim| str << "#{dim}: #{send(dim)}; " end str.strip end |
#ready_to_resolve?(hash) ⇒ Boolean
65 66 67 |
# File 'lib/bread/basket/poster/box.rb', line 65 def ready_to_resolve?(hash) hash[:pending].empty? && safe?(hash[:command]) end |
#resolve_box ⇒ Object
81 82 83 84 |
# File 'lib/bread/basket/poster/box.rb', line 81 def resolve_box layout.pending.delete selector_name unfinished.each { |dimension| determine_missing dimension } end |
#resolve_dimension(dimension, hash) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/bread/basket/poster/box.rb', line 56 def resolve_dimension(dimension, hash) command_string = hash[:command].join(' ') value = eval command_string instance_variable_set "@#{dimension}", value pending.delete dimension add_to_determined dimension, value resolve_box if pending.empty? end |
#safe?(command_array) ⇒ Boolean
69 70 71 72 73 |
# File 'lib/bread/basket/poster/box.rb', line 69 def safe?(command_array) command_array.all? do |elem| (elem.is_a? Numeric) || ([:+, :-, :/, :*, '(', ')'].include?(elem)) end end |
#setup_dimensions ⇒ Object
33 34 35 36 |
# File 'lib/bread/basket/poster/box.rb', line 33 def setup_dimensions DimensionsHelper.new(self, layout, specs) layout.pending << selector_name unless pending.empty? end |
#stretchy? ⇒ Boolean
113 114 115 |
# File 'lib/bread/basket/poster/box.rb', line 113 def stretchy? !stretchy.nil? end |
#try_dimension(dimensions_hash) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/bread/basket/poster/box.rb', line 46 def try_dimension(dimensions_hash) dimensions_hash[:pending].delete_if do |dimension_key, index| value = layout.determined[dimension_key] if value && value != :stretchy command_arr = dimensions_hash[:command] command_arr[index] = value end end end |
#try_to_resolve ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/bread/basket/poster/box.rb', line 38 def try_to_resolve pending.each do |dimension| hash = send dimension try_dimension hash resolve_dimension(dimension, hash) if ready_to_resolve? hash end end |