Class: NSAStorage::Dimensions
- Inherits:
-
Object
- Object
- NSAStorage::Dimensions
- Defined in:
- lib/nsastorage/dimensions.rb
Overview
The dimensions (width + depth + sqft) of a price.
Constant Summary collapse
- DEFAULT_WIDTH =
feet
5.0
- DEFAULT_DEPTH =
feet
5.0
- DEFAULT_HEIGHT =
feet
8.0
- DIMENSIONS_REGEX =
/(?<width>[\d\.]+) x (?<depth>[\d\.]+)/
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #cuft ⇒ Integer
-
#id ⇒ String
E.g.
-
#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.
27 28 29 30 31 |
# File 'lib/nsastorage/dimensions.rb', line 27 def initialize(depth:, width:, height: DEFAULT_HEIGHT) @depth = depth @width = width @height = height end |
Instance Attribute Details
#depth ⇒ Float
14 15 16 |
# File 'lib/nsastorage/dimensions.rb', line 14 def depth @depth end |
#height ⇒ Float
22 23 24 |
# File 'lib/nsastorage/dimensions.rb', line 22 def height @height end |
#width ⇒ Float
18 19 20 |
# File 'lib/nsastorage/dimensions.rb', line 18 def width @width end |
Class Method Details
.parse(element:) ⇒ Dimensions
66 67 68 69 70 71 72 73 |
# File 'lib/nsastorage/dimensions.rb', line 66 def self.parse(element:) text = element.at_css('.unit-select-item-detail').text match = DIMENSIONS_REGEX.match(text) width = match ? Float(match[:width]) : DEFAULT_WIDTH depth = match ? Float(match[:depth]) : DEFAULT_DEPTH new(depth:, width:, height: DEFAULT_HEIGHT) end |
Instance Method Details
#cuft ⇒ Integer
54 55 56 |
# File 'lib/nsastorage/dimensions.rb', line 54 def cuft Integer(@width * @depth * @height) end |
#id ⇒ String
Returns e.g. “5×5”.
44 45 46 |
# File 'lib/nsastorage/dimensions.rb', line 44 def id "#{format('%g', @width)}×#{format('%g', @depth)}" end |
#inspect ⇒ String
34 35 36 37 38 39 40 41 |
# File 'lib/nsastorage/dimensions.rb', line 34 def inspect props = [ "depth=#{@depth.inspect}", "width=#{@width.inspect}", "height=#{@height.inspect}" ] "#<#{self.class.name} #{props.join(' ')}>" end |
#sqft ⇒ Integer
49 50 51 |
# File 'lib/nsastorage/dimensions.rb', line 49 def sqft Integer(@width * @depth) end |
#text ⇒ String
Returns e.g. “10’ × 10’ (100 sqft)”.
59 60 61 |
# File 'lib/nsastorage/dimensions.rb', line 59 def text "#{format('%g', @width)}' × #{format('%g', @depth)}' (#{sqft} sqft)" end |