Class: Velibe::StationStatus
- Inherits:
-
Object
- Object
- Velibe::StationStatus
- Defined in:
- lib/velibe/station_status.rb
Instance Attribute Summary collapse
-
#available_bike_stands ⇒ Object
readonly
Returns the value of attribute available_bike_stands.
-
#available_bikes ⇒ Object
readonly
Returns the value of attribute available_bikes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .from_hash(json) ⇒ Object
-
.print_from_json(json_string, prefix = '') ⇒ Object
MAYBE Might belong in formater?.
- .string_from_json(json) ⇒ Object
Instance Method Summary collapse
-
#can_go? ⇒ Boolean
MAYBE REPLACE VALUE: 0 no, 1 un peu, 2 attention.
- #can_go_to?(station) ⇒ Boolean
-
#can_leave? ⇒ Boolean
FIXME: replace comment with doc TODO: maybe extract in Trajet: + method: velo dispo, stand dispo.
-
#initialize(name, available_bikes, available_bike_stands) ⇒ StationStatus
constructor
A new instance of StationStatus.
- #to_csv(sep = ';') ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, available_bikes, available_bike_stands) ⇒ StationStatus
Returns a new instance of StationStatus.
7 8 9 10 11 12 13 |
# File 'lib/velibe/station_status.rb', line 7 def initialize (name, available_bikes, available_bike_stands) # Maybe: enhance with bike_stand, and last_update @name= name @available_bikes = available_bikes @available_bike_stands= available_bike_stands # TODO: creation Timestamp end |
Instance Attribute Details
#available_bike_stands ⇒ Object (readonly)
Returns the value of attribute available_bike_stands.
5 6 7 |
# File 'lib/velibe/station_status.rb', line 5 def available_bike_stands @available_bike_stands end |
#available_bikes ⇒ Object (readonly)
Returns the value of attribute available_bikes.
5 6 7 |
# File 'lib/velibe/station_status.rb', line 5 def available_bikes @available_bikes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/velibe/station_status.rb', line 5 def name @name end |
Class Method Details
.from_hash(json) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/velibe/station_status.rb', line 42 def self.from_hash(json) # TODO: sanity check of jzon name = json[:name].capitalize #RAISE EROR if neede available_bikes = json[:available_bikes] available_bike_stands = json[:available_bike_stands] # T self.new(name, available_bikes, available_bike_stands) end |
.print_from_json(json_string, prefix = '') ⇒ Object
MAYBE Might belong in formater?
52 53 54 55 56 57 |
# File 'lib/velibe/station_status.rb', line 52 def self.print_from_json(json_string, prefix='') data = JSON.parse(json_string, symbolize_names: true) status = StationStatus.from_hash(data) puts "#{prefix}#{status}" status end |
.string_from_json(json) ⇒ Object
38 39 40 |
# File 'lib/velibe/station_status.rb', line 38 def self.string_from_json(json) StationStatus.from_hash(json).to_s end |
Instance Method Details
#can_go? ⇒ Boolean
MAYBE REPLACE VALUE: 0 no, 1 un peu, 2 attention
30 31 32 |
# File 'lib/velibe/station_status.rb', line 30 def can_go? @available_bike_stands > 0 and not @available_bike_stands # test si nil quand pas de velo end |
#can_go_to?(station) ⇒ Boolean
34 35 36 |
# File 'lib/velibe/station_status.rb', line 34 def can_go_to?(station) self.can_leave? and station.can_go? end |
#can_leave? ⇒ Boolean
FIXME: replace comment with doc TODO: maybe extract in Trajet: + method: velo dispo, stand dispo
25 26 27 |
# File 'lib/velibe/station_status.rb', line 25 def can_leave? @available_bikes > 0 and not @available_bikes.nil? # test si nil quand pas de velo end |
#to_csv(sep = ';') ⇒ Object
19 20 21 |
# File 'lib/velibe/station_status.rb', line 19 def to_csv(sep = ';') [@name, @available_bikes, @available_bike_stands].join(sep) end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/velibe/station_status.rb', line 15 def to_s "Station #{@name}: #{@available_bikes} Velo(s) libre(s) pour #{@available_bike_stands} places libres" end |