Class: Boxbot::Compute::TabCalculator
- Inherits:
-
Object
- Object
- Boxbot::Compute::TabCalculator
- Defined in:
- lib/boxbot/compute/tab_calculator.rb
Overview
Computes the actual tab with for a given dimension index or name.
Instance Attribute Summary collapse
-
#dimensions ⇒ Boxbot::Dimensions
instance.
Instance Method Summary collapse
-
#[](dimension_identifier) ⇒ Integer
Computes the tab count for a given dimension, and returns an integer result.
-
#calculate(dimension_identifier) ⇒ TabWidthResult
Computes the tab width for a given dimension, and returns a TabWithResult struct.
-
#initialize(dimensions) ⇒ TabCalculator
constructor
A new instance of TabCalculator.
Constructor Details
#initialize(dimensions) ⇒ TabCalculator
32 33 34 |
# File 'lib/boxbot/compute/tab_calculator.rb', line 32 def initialize(dimensions) self.dimensions = dimensions end |
Instance Attribute Details
#dimensions ⇒ Boxbot::Dimensions
instance
29 30 31 |
# File 'lib/boxbot/compute/tab_calculator.rb', line 29 def dimensions @dimensions end |
Instance Method Details
#[](dimension_identifier) ⇒ Integer
Computes the tab count for a given dimension, and returns an integer result.
63 64 65 66 67 68 69 |
# File 'lib/boxbot/compute/tab_calculator.rb', line 63 def [](dimension_identifier) tab_count_for_length( dimension_length( dimension_identifier ) ) end |
#calculate(dimension_identifier) ⇒ TabWidthResult
Computes the tab width for a given dimension, and returns a TabWithResult struct.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/boxbot/compute/tab_calculator.rb', line 45 def calculate(dimension_identifier) index = resolve_dimension_argument(dimension_identifier) length = dimensions.inner_box[index] tab_count = tab_count_for_length(length) tab_width = length / tab_count TabWidthResult.new(Types::Dimensions[index], length, tab_count, tab_width) end |