Class: Snafu::Models::Hub

Inherits:
Location show all
Defined in:
lib/snafu/models/hub.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Location

#name

Instance Method Summary collapse

Methods inherited from Location

#initializer

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(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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/snafu/models/hub.rb', line 6

def id
  @id
end

#streetsObject (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_sObject



30
31
32
# File 'lib/snafu/models/hub.rb', line 30

def to_s
  "Glitch Hub - ID: #{self.id} Name: #{self.name}"
end