Class: Snafu::Models::Street

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

Instance Attribute Summary collapse

Attributes inherited from Location

#name

Instance Method Summary collapse

Methods inherited from Location

#id, #initializer

Constructor Details

#initialize(options = {}) ⇒ Street

Returns a new instance of Street



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/snafu/models/street.rb', line 7

def initialize(options = {})
  if options.class == HTTParty::Response
    @id = options["tsid"]
    @name = options["name"]
    @hub = Hub.new(:id => options["hub"]["id"], :name => options["hub"]["name"])
    @features = options["features"]
    @connections = []
    options["connections"].each do |street_id, street|
      @connections << Street.new(
        :id => street_id,
        :name => street["name"],
        :hub => Hub.new(:id => options["hub"]["id"], :name => options["hub"]["name"]),
        :mote => Hub.new(:id => options["mote"]["id"], :name => options["mote"]["name"]),
      )
    end
    @mote = Hub.new(:id => options["mote"]["id"], :name => options["mote"]["name"])

    unless options["image"].nil?
      @image = GlitchImage.new(
        :url => options["image"]["url"],
        :width => options["image"]["w"],
        :height => options["image"]["h"]
      )
    end

    @active_project = options["active_project"]
  else
    @id = options[:id]
    @name = options[:name]
    @hub = options[:hub]
    @features = options[:features]
    @connections = options[:connections] || []
    @mote = options[:mote]
    @image = options[:image]
    @active_project = options[:active_project] || false
  end
end

Instance Attribute Details

#active_projectObject (readonly) Also known as: active_project?

Returns the value of attribute active_project



4
5
6
# File 'lib/snafu/models/street.rb', line 4

def active_project
  @active_project
end

#connectionsObject (readonly)

Returns the value of attribute connections



4
5
6
# File 'lib/snafu/models/street.rb', line 4

def connections
  @connections
end

#featuresObject (readonly)

Returns the value of attribute features



4
5
6
# File 'lib/snafu/models/street.rb', line 4

def features
  @features
end

#hubObject (readonly)

Returns the value of attribute hub



4
5
6
# File 'lib/snafu/models/street.rb', line 4

def hub
  @hub
end

#imageObject (readonly)

Returns the value of attribute image



4
5
6
# File 'lib/snafu/models/street.rb', line 4

def image
  @image
end

#moteObject (readonly)

Returns the value of attribute mote



4
5
6
# File 'lib/snafu/models/street.rb', line 4

def mote
  @mote
end

Instance Method Details

#to_sObject



44
45
46
# File 'lib/snafu/models/street.rb', line 44

def to_s
  "Glitch Street: #{self.id} - #{self.name}"
end