Class: UHaul::Features
- Inherits:
-
Object
- Object
- UHaul::Features
- Defined in:
- lib/uhaul/features.rb
Overview
The features (e.g. climate-controlled, inside-drive-up-access, outside-drive-up-access, etc) of a price.
Class Method Summary collapse
Instance Method Summary collapse
- #amenities ⇒ Array<String>
- #climate_controlled? ⇒ Boolean
- #drive_up_access? ⇒ Boolean
- #first_floor_access? ⇒ Boolean
-
#initialize(climate_controlled:, drive_up_access:, first_floor_access:) ⇒ Features
constructor
A new instance of Features.
- #inspect ⇒ String
-
#text ⇒ String
E.g.
Constructor Details
#initialize(climate_controlled:, drive_up_access:, first_floor_access:) ⇒ Features
Returns a new instance of Features.
20 21 22 23 24 |
# File 'lib/uhaul/features.rb', line 20 def initialize(climate_controlled:, drive_up_access:, first_floor_access:) @climate_controlled = climate_controlled @drive_up_access = drive_up_access @first_floor_access = first_floor_access end |
Class Method Details
.parse(text:) ⇒ Features
9 10 11 12 13 14 15 |
# File 'lib/uhaul/features.rb', line 9 def self.parse(text:) new( climate_controlled: text.include?('Climate') && !text.include?('No Climate'), drive_up_access: text.include?('Drive Up'), first_floor_access: text.include?('1st Floor') ) end |
Instance Method Details
#amenities ⇒ Array<String>
43 44 45 46 47 48 49 |
# File 'lib/uhaul/features.rb', line 43 def amenities [].tap do |amenities| amenities << 'Climate Controlled' if climate_controlled? amenities << 'Drive-Up Access' if drive_up_access? amenities << 'First Floor Access' if first_floor_access? end end |
#climate_controlled? ⇒ Boolean
52 53 54 |
# File 'lib/uhaul/features.rb', line 52 def climate_controlled? @climate_controlled end |
#drive_up_access? ⇒ Boolean
57 58 59 |
# File 'lib/uhaul/features.rb', line 57 def drive_up_access? @drive_up_access end |
#first_floor_access? ⇒ Boolean
62 63 64 |
# File 'lib/uhaul/features.rb', line 62 def first_floor_access? @first_floor_access end |
#inspect ⇒ String
27 28 29 30 31 32 33 34 35 |
# File 'lib/uhaul/features.rb', line 27 def inspect props = [ "climate_controlled=#{@climate_controlled}", "drive_up_access=#{@drive_up_access}", "first_floor_access=#{@first_floor_access}" ] "#<#{self.class.name} #{props.join(' ')}>" end |
#text ⇒ String
Returns e.g. “Climate Controlled + First Floor Access”.
38 39 40 |
# File 'lib/uhaul/features.rb', line 38 def text amenities.join(' + ') end |