Class: Mikrotik::Protocol::Sentence

Inherits:
Hash
  • Object
show all
Defined in:
lib/mikrotik/protocol/sentence.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Fetches any returned value in this reply, converting it to a ruby type first



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mikrotik/protocol/sentence.rb', line 48

def [](key)
  return nil unless key?(key)
  case key
  when '.tag'
    fetch(key).to_i
  else
    value = fetch(key)
    #case value
    #when /\d+/
    #  value.to_i
    #when /\d+.\d+/
    #  value.to_f
    #when 'true'
    #  true
    #when 'false'
    #  false
    #else
    #  value
    #end
  end
end

#completely_done?Boolean

Is this reply only informing that a command is done, and contains no other data?

Returns:

  • (Boolean)


17
18
19
# File 'lib/mikrotik/protocol/sentence.rb', line 17

def completely_done?
  size == 2 and done? and tagged?
end

#done?Boolean

Is this the last reply for a command?

Returns:

  • (Boolean)


11
12
13
# File 'lib/mikrotik/protocol/sentence.rb', line 11

def done?
  key?('!done')
end

#empty?Boolean

Sentence only contains a zero length word

Returns:

  • (Boolean)


5
6
7
# File 'lib/mikrotik/protocol/sentence.rb', line 5

def empty?
  super || false
end

#result(key) ⇒ Object

Fetches a returned property

Returns:

  • value



43
44
45
# File 'lib/mikrotik/protocol/sentence.rb', line 43

def result(key)
  self["=#{key}"]
end

#tagnil, Integer

Retreives the reply's command tag

Returns:

  • (nil)

    If the command is not tagged

  • (Integer)

    tag If the command is tagged



37
38
39
# File 'lib/mikrotik/protocol/sentence.rb', line 37

def tag
  tagged? ? self['.tag'] : nil
end

#tagged?Boolean

Does the reply have a command tag associated with it?

Returns:

  • (Boolean)


29
30
31
# File 'lib/mikrotik/protocol/sentence.rb', line 29

def tagged?
  key?('.tag')
end

#trap?Boolean

Is this informing of an error that should be trapped?

Returns:

  • (Boolean)


23
24
25
# File 'lib/mikrotik/protocol/sentence.rb', line 23

def trap?
  key?('!trap')
end