Class: SpeedtestNet::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/speedtest_net/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, url, geo, distance, server) ⇒ Server

Returns a new instance of Server.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/speedtest_net/server.rb', line 15

def initialize(id, url, geo, distance, server)
  @id = id
  @url = url
  @geo = geo
  @distance = distance
  @name = server['name']
  @country = server['country']
  @cc = server['cc']
  @sponsor = server['sponsor']
  @host = server['host']
  @latency = nil
end

Instance Attribute Details

#ccObject (readonly)

Returns the value of attribute cc.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def cc
  @cc
end

#countryObject (readonly)

Returns the value of attribute country.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def country
  @country
end

#distanceObject (readonly)

Returns the value of attribute distance.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def distance
  @distance
end

#geoObject (readonly)

Returns the value of attribute geo.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def geo
  @geo
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def host
  @host
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def id
  @id
end

#latencyObject

Returns the value of attribute latency.



13
14
15
# File 'lib/speedtest_net/server.rb', line 13

def latency
  @latency
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def name
  @name
end

Returns the value of attribute sponsor.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def sponsor
  @sponsor
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/speedtest_net/server.rb', line 11

def url
  @url
end

Class Method Details

.listObject



33
34
35
36
37
38
39
# File 'lib/speedtest_net/server.rb', line 33

def list
  xml_servers = fetch_servers
  servers = xml_servers.map do |server|
    create_instance(server)
  end
  servers.sort_by { |s| [s.distance, s.id] }
end

.select_server(id = nil, exclude_server_ids = []) ⇒ Object



41
42
43
# File 'lib/speedtest_net/server.rb', line 41

def select_server(id = nil, exclude_server_ids = [])
  id.nil? ? best_server(exclude_server_ids) : pick_server(id)
end

Instance Method Details

#measure_latencyObject



28
29
30
# File 'lib/speedtest_net/server.rb', line 28

def measure_latency
  @latency = Latency.measure(self)
end