Class: Location

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

Constant Summary collapse

MARKERS_URL =
"http://www.purdue.edu/campus_map/xml/MarkersAll5.xml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abbr) ⇒ Location

Returns a new instance of Location.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/purlocation/location.rb', line 19

def initialize abbr
  @me = self.class.markers_hash.select do |marker|
    marker["@abbreviation"] == abbr
  end.first

  @me.keys.each do |k|
    meth = k[1..-1]
    self.class.send( :define_method, meth ) do
      return @me["@#{meth}"]
    end
  end
end

Instance Attribute Details

#abbrObject

Returns the value of attribute abbr.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def abbr
  @abbr
end

#cityObject

Returns the value of attribute city.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def city
  @city
end

#latObject

Returns the value of attribute lat.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def lat
  @lat
end

#longObject

Returns the value of attribute long.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def long
  @long
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def name
  @name
end

#stateObject

Returns the value of attribute state.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def state
  @state
end

#street_addressObject

Returns the value of attribute street_address.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def street_address
  @street_address
end

#zipObject

Returns the value of attribute zip.



6
7
8
# File 'lib/purlocation/location.rb', line 6

def zip
  @zip
end

Class Method Details

.markers_hashObject



9
10
11
# File 'lib/purlocation/location.rb', line 9

def self.markers_hash
  @markers_hash ||= populate_markers
end

.populate_markersObject



13
14
15
16
17
# File 'lib/purlocation/location.rb', line 13

def self.populate_markers
  xml_data = Net::HTTP.get_response(URI.parse(MARKERS_URL)).body
  parser = Nori.new( :parser=> :rexml)
  @markers_hash = parser.parse(xml_data)["markers"].first[1]
end