Class: Bikepoint

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

Overview

A bike point with a rack of cycles for hire.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_json) ⇒ Bikepoint


21
22
23
24
25
26
# File 'lib/bikepoint.rb', line 21

def initialize(raw_json)
  @raw_json = raw_json
  @name = @raw_json['commonName']
  @bikes = additional_property('NbBikes')
  @spaces = additional_property('NbEmptyDocks')
end

Instance Attribute Details

#bikesObject (readonly)

Returns the value of attribute bikes


19
20
21
# File 'lib/bikepoint.rb', line 19

def bikes
  @bikes
end

#nameObject (readonly)

Returns the value of attribute name


19
20
21
# File 'lib/bikepoint.rb', line 19

def name
  @name
end

#spacesObject (readonly)

Returns the value of attribute spaces


19
20
21
# File 'lib/bikepoint.rb', line 19

def spaces
  @spaces
end

Class Method Details

.allObject


7
8
9
# File 'lib/bikepoint.rb', line 7

def self.all
  @bikepoints ||= all_json.map { |j| [j['commonName'], Bikepoint.new(j)] }.to_h
end

.all_jsonObject


11
12
13
# File 'lib/bikepoint.rb', line 11

def self.all_json
  JSON.parse(RestClient.get(ENV['BIKEPOINT_API_URL']))
end

.all_namesObject


15
16
17
# File 'lib/bikepoint.rb', line 15

def self.all_names
  all.keys
end

Instance Method Details

#additional_property(property) ⇒ Object


28
29
30
# File 'lib/bikepoint.rb', line 28

def additional_property(property)
  @raw_json['additionalProperties'].find { |p| p['key'] == property }['value']
end