Class: CubeSmart::Dimensions
- Inherits:
-
Object
- Object
- CubeSmart::Dimensions
- Defined in:
- lib/cubesmart/dimensions.rb
Overview
The dimensions (width + depth + sqft) of a price.
Constant Summary collapse
- DEFAULT_HEIGHT =
feet
8.0
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #cuft ⇒ Integer
-
#initialize(depth:, width:, height: DEFAULT_HEIGHT) ⇒ Dimensions
constructor
A new instance of Dimensions.
- #inspect ⇒ String
- #sqft ⇒ Integer
-
#text ⇒ String
E.g.
Constructor Details
#initialize(depth:, width:, height: DEFAULT_HEIGHT) ⇒ Dimensions
Returns a new instance of Dimensions.
23 24 25 26 27 |
# File 'lib/cubesmart/dimensions.rb', line 23 def initialize(depth:, width:, height: DEFAULT_HEIGHT) @depth = depth @width = width @height = height end |
Instance Attribute Details
#depth ⇒ Float
10 11 12 |
# File 'lib/cubesmart/dimensions.rb', line 10 def depth @depth end |
#height ⇒ Float
18 19 20 |
# File 'lib/cubesmart/dimensions.rb', line 18 def height @height end |
#width ⇒ Float
14 15 16 |
# File 'lib/cubesmart/dimensions.rb', line 14 def width @width end |
Class Method Details
.parse(element:) ⇒ Dimensions
57 58 59 60 61 62 63 64 65 |
# File 'lib/cubesmart/dimensions.rb', line 57 def self.parse(element:) text = element.text match = text.match(/(?<width>[\d\.]+)'x(?<depth>[\d\.]+)'/) raise text.inspect if match.nil? width = Float(match[:width]) depth = Float(match[:depth]) new(depth:, width:, height: DEFAULT_HEIGHT) end |
Instance Method Details
#cuft ⇒ Integer
45 46 47 |
# File 'lib/cubesmart/dimensions.rb', line 45 def cuft Integer(@width * @depth * @height) end |
#inspect ⇒ String
30 31 32 33 34 35 36 37 |
# File 'lib/cubesmart/dimensions.rb', line 30 def inspect props = [ "depth=#{@depth.inspect}", "width=#{@width.inspect}", "height=#{@height.inspect}" ] "#<#{self.class.name} #{props.join(' ')}>" end |
#sqft ⇒ Integer
40 41 42 |
# File 'lib/cubesmart/dimensions.rb', line 40 def sqft Integer(@width * @depth) end |
#text ⇒ String
Returns e.g. “10’ × 10’ (100 sqft)”.
50 51 52 |
# File 'lib/cubesmart/dimensions.rb', line 50 def text "#{format('%g', @width)}' × #{format('%g', @depth)}' (#{sqft} sqft)" end |