module Havox::FieldParser

Public Instance Methods

basic_action(action, arg_a = nil, arg_b = nil) click to toggle source
# File lib/havox/modules/field_parser.rb, line 11
def basic_action(action, arg_a = nil, arg_b = nil)
  { action: action, arg_a: arg_a, arg_b: arg_b }
end
parsed_ipv4(ip_integer) click to toggle source
# File lib/havox/modules/field_parser.rb, line 3
def parsed_ipv4(ip_integer)
  ip_integer = ip_integer.to_i
  value = ip_integer.positive? ? ip_integer : (2**32 - ip_integer.abs)      # Handles two's complement integers.
  bits = value.to_s(2).rjust(32, '0')                                       # Transforms the string number into a 32-bit sequence.
  octets = bits.scan(/\d{8}/).map { |octet_bits| octet_bits.to_i(2) }       # Splits the sequence into decimal octets.
  octets.join('.')                                                          # Returns the joined octets.
end
raise_unknown_action(obj) click to toggle source
# File lib/havox/modules/field_parser.rb, line 15
def raise_unknown_action(obj)
  raise Havox::UnknownAction,
    "Unable to translate action #{obj[:action]} with arguments A:"         \
    " #{obj[:arg_a]} and B: #{obj[:arg_b]}, respectively"
end