Class: CubeSmart::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/cubesmart/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

Constructor Details

#initialize(climate_controlled:, inside_drive_up_access:, outside_drive_up_access:, first_floor_access:) ⇒ Features

Returns a new instance of Features.

Parameters:

  • climate_controlled (Boolean)
  • inside_drive_up_access (Boolean)
  • outside_drive_up_access (Boolean)
  • first_floor_access (Boolean)


24
25
26
27
28
29
# File 'lib/cubesmart/features.rb', line 24

def initialize(climate_controlled:, inside_drive_up_access:, outside_drive_up_access:, first_floor_access:)
  @climate_controlled = climate_controlled
  @inside_drive_up_access = inside_drive_up_access
  @outside_drive_up_access = outside_drive_up_access
  @first_floor_access = first_floor_access
end

Class Method Details

.parse(element:) ⇒ Features

Parameters:

  • element (Nokogiri::XML::Element)

Returns:



9
10
11
12
13
14
15
16
17
18
# File 'lib/cubesmart/features.rb', line 9

def self.parse(element:)
  text = element.text

  new(
    climate_controlled: text.include?('Climate controlled'),
    inside_drive_up_access: text.include?('Inside drive-up access'),
    outside_drive_up_access: text.include?('Outside drive-up access'),
    first_floor_access: text.include?('1st floor access')
  )
end

Instance Method Details

#amenitiesArray<String>

Returns:

  • (Array<String>)


49
50
51
52
53
54
55
56
# File 'lib/cubesmart/features.rb', line 49

def amenities
  [].tap do |amenities|
    amenities << 'Climate Controlled' if climate_controlled?
    amenities << 'Inside Drive-Up Access' if inside_drive_up_access?
    amenities << 'Outside Drive-Up Access' if outside_drive_up_access?
    amenities << 'First Floor Access' if first_floor_access?
  end
end

#climate_controlled?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cubesmart/features.rb', line 59

def climate_controlled?
  @climate_controlled
end

#drive_up_access?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/cubesmart/features.rb', line 74

def drive_up_access?
  inside_drive_up_access? || outside_drive_up_access?
end

#first_floor_access?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/cubesmart/features.rb', line 79

def first_floor_access?
  @first_floor_access
end

#inside_drive_up_access?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/cubesmart/features.rb', line 64

def inside_drive_up_access?
  @inside_drive_up_access
end

#inspectString

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
# File 'lib/cubesmart/features.rb', line 32

def inspect
  props = [
    "climate_controlled=#{@climate_controlled}",
    "inside_drive_up_access=#{@inside_drive_up_access}",
    "outside_drive_up_access=#{@outside_drive_up_access}",
    "first_floor_access=#{@first_floor_access}"
  ]

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

#outside_drive_up_access?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/cubesmart/features.rb', line 69

def outside_drive_up_access?
  @outside_drive_up_access
end

#textString

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

Returns:

  • (String)

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



44
45
46
# File 'lib/cubesmart/features.rb', line 44

def text
  amenities.join(' + ')
end