Module: Crossover::Client
- Defined in:
- lib/crossover/client.rb
Class Method Summary collapse
- .clean_data(token = '') ⇒ Object
-
.clean_out_non_UTF8_compliant_chars(str, token = '') ⇒ Object
Returns a copy of String.
- .post(data, server, port) ⇒ Object
- .read_1024_bytes_from_dev_urandom ⇒ Object
- .replace_all_spaces_with_asterisk(str) ⇒ Object
Class Method Details
.clean_data(token = '') ⇒ Object
17 18 19 20 21 |
# File 'lib/crossover/client.rb', line 17 def self.clean_data(token = '') str = read_1024_bytes_from_dev_urandom clean = clean_out_non_UTF8_compliant_chars(str, token) replace_all_spaces_with_asterisk(clean) end |
.clean_out_non_UTF8_compliant_chars(str, token = '') ⇒ Object
Returns a copy of String
9 10 11 |
# File 'lib/crossover/client.rb', line 9 def self.clean_out_non_UTF8_compliant_chars(str, token = '') str.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: token) end |
.post(data, server, port) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/crossover/client.rb', line 23 def self.post(data , server, port) begin size = data.bytesize puts "Sending #{size} bytes to port #{port} on #{server}." socket = TCPSocket.open(server, port) puts data socket.write( data ) puts "\nBye!" socket.close rescue Errno::ECONNREFUSED puts "Sorry! Connection refused by #{server} on port #{port}" end end |
.read_1024_bytes_from_dev_urandom ⇒ Object
4 5 6 |
# File 'lib/crossover/client.rb', line 4 def self.read_1024_bytes_from_dev_urandom File.read("/dev/urandom", 1024) end |
.replace_all_spaces_with_asterisk(str) ⇒ Object
13 14 15 |
# File 'lib/crossover/client.rb', line 13 def self.replace_all_spaces_with_asterisk(str) str.gsub(/\s/, '*') end |