class Snafu::Models::Hub

Defines a class for Glitch Hubs, which are the various regions in the game.

Attributes

id[R]
streets[R]

Public Class Methods

new(options = {}) click to toggle source

Accepts either the raw JSON-formatted response from the HTTParty get request or an options hash.

# File lib/snafu/models/hub.rb, line 11
def initialize(options = {})
  if options.class == HTTParty::Response
    # construct the street information
    @id = options["hub_id"]
    @name = options["name"]
    @streets = []
    options["streets"].each do |street_id, street|
      @streets << Street.new(:id => street_id, :name => street["name"])
    end
  else
    @id = options[:id]
    @name = options[:name]
    if options[:streets].is_a? Array
      @streets = options[:streets]
    else
      @streets = [options[:streets]]
    end
  end
end

Public Instance Methods

to_s() click to toggle source
# File lib/snafu/models/hub.rb, line 30
def to_s
  "Glitch Hub - ID: #{self.id} Name: #{self.name}"
end