Class: MonogotoApi::Ping

Inherits:
Object
  • Object
show all
Defined in:
lib/monogoto_api/ping.rb,
lib/monogoto_api/ping/list.rb

Defined Under Namespace

Classes: List

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Ping

Returns a new instance of Ping.



7
8
9
10
11
12
13
14
15
# File 'lib/monogoto_api/ping.rb', line 7

def initialize(**attributes)
    @host        = attributes[:host]
    @size        = attributes[:size]
    @ttl         = attributes[:ttl]
    @time        = attributes[:time]
    @sent        = attributes[:sent]
    @received    = attributes[:received]
    @packet_loss = attributes[:packet_loss]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def host
  @host
end

#packet_lossObject (readonly)

Returns the value of attribute packet_loss.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def packet_loss
  @packet_loss
end

#receivedObject (readonly)

Returns the value of attribute received.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def received
  @received
end

#sentObject (readonly)

Returns the value of attribute sent.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def sent
  @sent
end

#sizeObject (readonly)

Returns the value of attribute size.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def size
  @size
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def time
  @time
end

#ttlObject (readonly)

Returns the value of attribute ttl.



5
6
7
# File 'lib/monogoto_api/ping.rb', line 5

def ttl
  @ttl
end

Class Method Details

.parse(hash_ping) ⇒ Object

Parser of single element of API ping response



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/monogoto_api/ping.rb', line 26

def self.parse(hash_ping)
    new(
        host: hash_ping["host"],
        size: hash_ping["size"].to_i,
        ttl: hash_ping["ttl"].to_i,
        time: hash_ping["time"],
        sent: hash_ping["sent"].to_i,
        received: hash_ping["received"].to_i,
        packet_loss: hash_ping["packetLoss"].to_i
    )
end

.parse_many(response) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/monogoto_api/ping.rb', line 17

def self.parse_many(response)
    output = []
    response.each do |pre_ip|
        output.push(parse(pre_ip))
    end
    output
end