Class: Upcoming::Metro

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, code, url, state, country) ⇒ Metro

Returns a new instance of Metro.



11
12
13
14
15
16
17
18
# File 'lib/upcoming/metro.rb', line 11

def initialize(id, name, code, url, state, country)
  @id = id
  @name = name
  @code = code
  @url = url
  @state = state
  @country = country
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/upcoming/metro.rb', line 9

def code
  @code
end

#countryObject (readonly)

Returns the value of attribute country.



9
10
11
# File 'lib/upcoming/metro.rb', line 9

def country
  @country
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/upcoming/metro.rb', line 9

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/upcoming/metro.rb', line 9

def name
  @name
end

#stateObject (readonly)

Returns the value of attribute state.



9
10
11
# File 'lib/upcoming/metro.rb', line 9

def state
  @state
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/upcoming/metro.rb', line 9

def url
  @url
end

Class Method Details

.countriesObject



63
64
65
# File 'lib/upcoming/metro.rb', line 63

def self.countries
  Upcoming::Country.get_all_infos
end

.get_by_lat_lon(lat, lon) ⇒ Object



51
52
53
# File 'lib/upcoming/metro.rb', line 51

def self.get_by_lat_lon(lat,lon)
  # TODO implement get_by_lat_lon
end

.get_info(metro_id) ⇒ Object



43
44
45
# File 'lib/upcoming/metro.rb', line 43

def self.get_info(metro_id)
  # TODO implement get_info
end

.get_infos(metro_id_list) ⇒ Object



47
48
49
# File 'lib/upcoming/metro.rb', line 47

def self.get_infos(metro_id_list)
  # TODO implement get_infos
end

.list_by_state(state_id) ⇒ Object



55
56
57
# File 'lib/upcoming/metro.rb', line 55

def self.list_by_state(state_id)
  # TODO implement list_by_state
end

.search(text, state_id = nil, country_id = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/upcoming/metro.rb', line 20

def self.search(text, state_id=nil, country_id=nil)
  metros = []
  
  req = Upcoming::Request.new
  resp = req.send({:method => 'metro.search', :search_text => text, 
                   :state_id => state_id, :country_id => country_id})
  
  doc = Document.new(resp.body)
  
  XPath.each(doc, '//metro') do |m|
    state = State.new(m.attribute('state_id').value, m.attribute('state_name').value,
        m.attribute('state_code').value, m.attribute('country_id').value)
        
    country = Country.new(m.attribute('country_id').value, m.attribute('country_name').value,
        m.attribute('country_code').value)
    
    metros << Metro.new(m.attribute('id').value, m.attribute('name').value,
        m.attribute('code').value, m.attribute('url').value, state, country)
  end
  
  metros
end

.states(country_id) ⇒ Object



59
60
61
# File 'lib/upcoming/metro.rb', line 59

def self.states(country_id)
  Upcoming::State.get_all_infos(country_id)
end