Class: NSAStorage::Features

Inherits:
Object
  • Object
show all
Defined in:
lib/nsastorage/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:, drive_up_access:, first_floor_access:) ⇒ Features

Returns a new instance of Features.

Parameters:

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


22
23
24
25
26
# File 'lib/nsastorage/features.rb', line 22

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(element:) ⇒ Features

Parameters:

  • element (Nokogiri::XML::Element)

Returns:



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

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

  new(
    climate_controlled: text.include?('Heated and Cooled'),
    drive_up_access: text.include?('Drive Up Access'),
    first_floor_access: text.include?('1st Floor')
  )
end

Instance Method Details

#amenitiesArray<String>

Returns:

  • (Array<String>)


54
55
56
57
58
59
60
# File 'lib/nsastorage/features.rb', line 54

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

Returns:

  • (Boolean)


63
64
65
# File 'lib/nsastorage/features.rb', line 63

def climate_controlled?
  @climate_controlled
end

#drive_up_access?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/nsastorage/features.rb', line 68

def drive_up_access?
  @drive_up_access
end

#first_floor_access?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/nsastorage/features.rb', line 73

def first_floor_access?
  @first_floor_access
end

#idString

Returns e.g. “”.

Returns:

  • (String)

    e.g. “”



40
41
42
43
44
45
46
# File 'lib/nsastorage/features.rb', line 40

def id
  [].tap do |ids|
    ids << 'cc' if climate_controlled?
    ids << 'dua' if drive_up_access?
    ids << 'ffa' if first_floor_access?
  end.join('-')
end

#inspectString

Returns:

  • (String)


29
30
31
32
33
34
35
36
37
# File 'lib/nsastorage/features.rb', line 29

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

#textString

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

Returns:

  • (String)

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



49
50
51
# File 'lib/nsastorage/features.rb', line 49

def text
  amenities.join(' + ')
end