Module: GamespyQuery::Funcs

Includes:
System::Net, System::Net::Sockets
Included in:
Base, Socket
Defined in:
lib/gamespy_query/base.rb

Defined Under Namespace

Classes: TimeOutError

Constant Summary collapse

RX_F =
/\A\-?[0-9][0-9]*\.[0-9]*\Z/
RX_I =
/\A\-?[0-9][0-9]*\Z/
RX_S =
/\A\-?0[0-9]+.*\Z/

Instance Method Summary collapse

Instance Method Details

#clean(value) ⇒ Object

TODO: Force String, Integer, Float etc?



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gamespy_query/base.rb', line 58

def clean(value) # TODO: Force String, Integer, Float etc?
  case value
    when STR_X0
      nil
    when RX_F
      value =~ RX_S ? strip_tags(value) : value.to_f
    when RX_I
      value =~ RX_S ? strip_tags(value) : value.to_i
    else
      strip_tags(value)
  end
end

#clean_string(str) ⇒ Object



71
72
73
# File 'lib/gamespy_query/base.rb', line 71

def clean_string(str)
  str.encode("UTF-8", invalid: :replace, undef: :replace)
end

#get_string(str) ⇒ Object



81
82
83
84
# File 'lib/gamespy_query/base.rb', line 81

def get_string(*params)
  Tools.debug {"Getting string #{params}"}
  _get_string(*params)
end

#handle_chr(number) ⇒ Object



75
76
77
78
79
# File 'lib/gamespy_query/base.rb', line 75

def handle_chr(number)
  number = ((number % 256)+256) if number < 0
  number = number % 256 if number > 255
  number
end

#strip_tags(str) ⇒ Object



49
50
51
52
# File 'lib/gamespy_query/base.rb', line 49

def strip_tags(str)
  # TODO: Strip tags!!
  str
end