Class: SpeedtestNet::Server
- Inherits:
-
Object
- Object
- SpeedtestNet::Server
- Defined in:
- lib/speedtest_net/server.rb
Instance Attribute Summary collapse
-
#cc ⇒ Object
readonly
Returns the value of attribute cc.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#geo ⇒ Object
readonly
Returns the value of attribute geo.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#latency ⇒ Object
Returns the value of attribute latency.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sponsor ⇒ Object
readonly
Returns the value of attribute sponsor.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, url, geo, distance, server) ⇒ Server
constructor
A new instance of Server.
- #measure_latency ⇒ Object
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
#cc ⇒ Object (readonly)
Returns the value of attribute cc.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def cc @cc end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def country @country end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def distance @distance end |
#geo ⇒ Object (readonly)
Returns the value of attribute geo.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def geo @geo end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def host @host end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def id @id end |
#latency ⇒ Object
Returns the value of attribute latency.
13 14 15 |
# File 'lib/speedtest_net/server.rb', line 13 def latency @latency end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def name @name end |
#sponsor ⇒ Object (readonly)
Returns the value of attribute sponsor.
11 12 13 |
# File 'lib/speedtest_net/server.rb', line 11 def sponsor @sponsor end |
#url ⇒ Object (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
.list ⇒ Object
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 |