Class: Snafu::Models::Hub
Overview
Defines a class for Glitch Hubs, which are the various regions in the game.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#streets ⇒ Object
readonly
Returns the value of attribute streets.
Attributes inherited from Location
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Hub
constructor
Accepts either the raw JSON-formatted response from the HTTParty get request or an options hash.
- #to_s ⇒ Object
Methods inherited from Location
Constructor Details
#initialize(options = {}) ⇒ Hub
Accepts either the raw JSON-formatted response from the HTTParty get request or an options hash.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/snafu/models/hub.rb', line 11 def initialize( = {}) if .class == HTTParty::Response # construct the street information @id = ["hub_id"] @name = ["name"] @streets = [] ["streets"].each do |street_id, street| @streets << Street.new(:id => street_id, :name => street["name"]) end else @id = [:id] @name = [:name] if [:streets].is_a? Array @streets = [:streets] else @streets = [[:streets]] end end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/snafu/models/hub.rb', line 6 def id @id end |
#streets ⇒ Object (readonly)
Returns the value of attribute streets.
6 7 8 |
# File 'lib/snafu/models/hub.rb', line 6 def streets @streets end |
Instance Method Details
#to_s ⇒ Object
30 31 32 |
# File 'lib/snafu/models/hub.rb', line 30 def to_s "Glitch Hub - ID: #{self.id} Name: #{self.name}" end |