Class: PublicStorage::Dimensions
- Inherits:
-
Object
- Object
- PublicStorage::Dimensions
- Defined in:
- lib/publicstorage/dimensions.rb
Overview
The dimensions (width + depth + sqft) of a price.
Constant Summary collapse
- SELECTOR =
'.unit-size'
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(depth:, width:, sqft:) ⇒ Dimensions
constructor
A new instance of Dimensions.
- #inspect ⇒ String
-
#text ⇒ String
E.g.
Constructor Details
#initialize(depth:, width:, sqft:) ⇒ Dimensions
Returns a new instance of Dimensions.
23 24 25 26 27 |
# File 'lib/publicstorage/dimensions.rb', line 23 def initialize(depth:, width:, sqft:) @depth = depth @width = width @sqft = sqft end |
Instance Attribute Details
#depth ⇒ Integer
10 11 12 |
# File 'lib/publicstorage/dimensions.rb', line 10 def depth @depth end |
#sqft ⇒ Integer
18 19 20 |
# File 'lib/publicstorage/dimensions.rb', line 18 def sqft @sqft end |
#width ⇒ Integer
14 15 16 |
# File 'lib/publicstorage/dimensions.rb', line 14 def width @width end |
Class Method Details
.parse(data:) ⇒ Dimensions
47 48 49 50 51 52 53 54 |
# File 'lib/publicstorage/dimensions.rb', line 47 def self.parse(data:) match = data['dimension'].match(/(?<depth>[\d\.]+)'x(?<width>[\d\.]+)'/) depth = Float(match[:depth]) width = Float(match[:width]) sqft = Integer(depth * width) new(depth:, width:, sqft:) end |
Instance Method Details
#inspect ⇒ String
30 31 32 33 34 35 36 37 |
# File 'lib/publicstorage/dimensions.rb', line 30 def inspect props = [ "depth=#{@depth.inspect}", "width=#{@width.inspect}", "sqft=#{@sqft.inspect}" ] "#<#{self.class.name} #{props.join(' ')}>" end |
#text ⇒ String
Returns e.g. “10’ × 10’ (100 sqft)”.
40 41 42 |
# File 'lib/publicstorage/dimensions.rb', line 40 def text "#{format('%g', @width)}' × #{format('%g', @depth)}' (#{@sqft} sqft)" end |