Class: ExtraSpace::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/extraspace/features.rb

Overview

The features (e.g. climate-controlled, inside-drive-up-access, outside-drive-up-access, etc) of a price.

Constant Summary collapse

FIRST_FLOOR_ACCESS_NAME =
'1stFloorAccess'
CLIMATE_CONTROLLED_NAME =
'ClimateControlled'
DRIVE_UP_ACCESS_NAME =
'DriveUpAccess'
ELEVATOR_ACCESS_NAME =
'ElevatorAccess'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(climate_controlled:, drive_up_access:, elevator_access:, first_floor_access:) ⇒ Features

Returns a new instance of Features.

Parameters:

  • climate_controlled (Boolean)
  • drive_up_access (Boolean)
  • first_floor_access (Boolean)


26
27
28
29
30
31
# File 'lib/extraspace/features.rb', line 26

def initialize(climate_controlled:, drive_up_access:, elevator_access:, first_floor_access:)
  @climate_controlled = climate_controlled
  @drive_up_access = drive_up_access
  @elevator_access = elevator_access
  @first_floor_access = first_floor_access
end

Class Method Details

.parse(data:) ⇒ Features

Parameters:

  • data (Array<Hash>)

Returns:



14
15
16
17
18
19
20
21
# File 'lib/extraspace/features.rb', line 14

def self.parse(data:)
  new(
    climate_controlled: data.any? { |feature| feature['name'].eql?(CLIMATE_CONTROLLED_NAME) },
    drive_up_access: data.any? { |feature| feature['name'].eql?(DRIVE_UP_ACCESS_NAME) },
    elevator_access: data.any? { |feature| feature['name'].eql?(ELEVATOR_ACCESS_NAME) },
    first_floor_access: data.any? { |feature| feature['name'].eql?(FIRST_FLOOR_ACCESS_NAME) }
  )
end

Instance Method Details

#amenitiesArray<String>

Returns:

  • (Array<String>)


51
52
53
54
55
56
57
58
# File 'lib/extraspace/features.rb', line 51

def amenities
  [].tap do |amenities|
    amenities << 'Climate Controlled' if climate_controlled?
    amenities << 'Drive-Up Access' if drive_up_access?
    amenities << 'Elevator Access' if elevator_access?
    amenities << 'First Floor Access' if first_floor_access?
  end
end

#climate_controlled?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/extraspace/features.rb', line 61

def climate_controlled?
  @climate_controlled
end

#drive_up_access?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/extraspace/features.rb', line 66

def drive_up_access?
  @drive_up_access
end

#elevator_access?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/extraspace/features.rb', line 71

def elevator_access?
  @elevator_access
end

#first_floor_access?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/extraspace/features.rb', line 76

def first_floor_access?
  @first_floor_access
end

#inspectString

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
43
# File 'lib/extraspace/features.rb', line 34

def inspect
  props = [
    "climate_controlled=#{@climate_controlled}",
    "drive_up_access=#{@drive_up_access}",
    "elevator_access=#{@elevator_access}",
    "first_floor_access=#{@first_floor_access}"
  ]

  "#<#{self.class.name} #{props.join(' ')}>"
end

#textString

Returns e.g. “Climate Controlled + First Floor Access”.

Returns:

  • (String)

    e.g. “Climate Controlled + First Floor Access”



46
47
48
# File 'lib/extraspace/features.rb', line 46

def text
  amenities.join(' + ')
end