Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/katcp/util.rb
Overview
String add-ons for KATCP
Instance Method Summary collapse
-
#katcp_escape ⇒ Object
Escapes
selfinto KATCP format and returns new String. -
#katcp_escape! ⇒ Object
In-place escapes
selfinto KATCP format. -
#katcp_unescape ⇒ Object
Unescapes
selffrom KATCP format and returns new String. -
#katcp_unescape! ⇒ Object
In-place unescapes
selffrom KATCP format. -
#to_na(typecode, *args) ⇒ Object
call-seq: to_na(typecode) -> NArray to_na(typecode, size[, …]) -> NArray.
Instance Method Details
#katcp_escape ⇒ Object
Escapes self into KATCP format and returns new String.
24 25 26 |
# File 'lib/katcp/util.rb', line 24 def katcp_escape dup.katcp_escape! end |
#katcp_escape! ⇒ Object
In-place escapes self into KATCP format. Always returns self.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/katcp/util.rb', line 8 def katcp_escape! empty? ? self[0..-1] = '\@' : self.gsub!(/[\\ \0\n\r\e\t]/) do |s| case s when "\\"; '\\\\' when " " ; '\_' when "\0"; '\0' when "\n"; '\n' when "\r"; '\r' when "\e"; '\e' when "\t"; '\t' end end self end |
#katcp_unescape ⇒ Object
Unescapes self from KATCP format and returns new String.
45 46 47 |
# File 'lib/katcp/util.rb', line 45 def katcp_unescape dup.katcp_unescape! end |
#katcp_unescape! ⇒ Object
In-place unescapes self from KATCP format. Always returns self.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/katcp/util.rb', line 29 def katcp_unescape! self == '\@' ? self[0..-1] = '' : self.gsub!(/\\[\\_0nret]/) do |s| case s when '\\\\'; "\\" when '\_'; " " when '\0'; "\0" when '\n'; "\n" when '\r'; "\r" when '\e'; "\e" when '\t'; "\t" end end self end |
#to_na(typecode, *args) ⇒ Object
call-seq:
to_na(typecode) -> NArray
to_na(typecode, size[, ...]) -> NArray
Convert String to NArray accoring to typecode.
54 55 56 |
# File 'lib/katcp/util.rb', line 54 def to_na(typecode, *args) NArray.to_na(self, typecode, *args) end |