Class: Gares::Base

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

Overview

Represents something on gare-en-mouvement.com

Direct Known Subclasses

Sales, Services, Station

Constant Summary collapse

GPS_COORD =
'Coordonnées GPS : '
NAME =
'En direct de '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slug, name = nil) ⇒ Base

Initialize a new Station object with it's gare-en-mouvemnt id (as a String)

station = Gares::Station.new("frabt")

Gares::Station objects are lazy loaded, meaning that no HTTP request will be performed when a new object is created. An HTTP request is made (once) Only when you use an accessor that needs the remote data.


17
18
19
20
# File 'lib/gares/base.rb', line 17

def initialize(slug, name = nil)
  @slug = slug
  @name = name if name
end

Instance Attribute Details

#name(force_refresh = false) ⇒ Object

Returns a string containing the name


62
63
64
# File 'lib/gares/base.rb', line 62

def name
  @name
end

#slugObject

Returns the value of attribute slug


4
5
6
# File 'lib/gares/base.rb', line 4

def slug
  @slug
end

Instance Method Details

#defibrillateur?Boolean Also known as: defibrillator?

Whether the gare has a defibrillator or not

Returns:

  • (Boolean)

47
48
49
# File 'lib/gares/base.rb', line 47

def defibrillateur?
  !document.at('div.defibrillateur').nil?
end

#has_borne?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/gares/base.rb', line 57

def has_borne?
  sales.any? { |sales_service| sales_service =~ /bornes?.libre.service/i }
end

#horairesObject Also known as: opening_hours


40
41
42
43
# File 'lib/gares/base.rb', line 40

def horaires
  document.search('ul.ouverture_heure li').
      map { |horaire| horaire.inner_html } rescue []
end

#latObject


22
23
24
# File 'lib/gares/base.rb', line 22

def lat
  coordinates.first.to_f
end

#longObject


26
27
28
# File 'lib/gares/base.rb', line 26

def long
  coordinates.last.to_f
end

#salesObject


35
36
37
38
# File 'lib/gares/base.rb', line 35

def sales
  @sales ||= Sales.new(@slug)
  @sales.all
end

#servicesObject


30
31
32
33
# File 'lib/gares/base.rb', line 30

def services
  @services ||= Services.new(@slug)
  @services.all
end

#wifi?Boolean

Whether the gare is equipped with wifi or not

Returns:

  • (Boolean)

53
54
55
# File 'lib/gares/base.rb', line 53

def wifi?
  !document.at('div.wifi').nil?
end