Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/icaprb/server/data_structures.rb
Overview
patch ruby strings
Direct Known Subclasses
Instance Method Summary collapse
-
#chunk_to_s ⇒ Object
extracts a ruby string from a chunk (chunked encoding).
-
#to_chunk ⇒ Object
converts the string to a chunk (chunked encoding).
Instance Method Details
#chunk_to_s ⇒ Object
extracts a ruby string from a chunk (chunked encoding)
8 9 10 11 12 13 14 15 16 |
# File 'lib/icaprb/server/data_structures.rb', line 8 def chunk_to_s len_alpha = scan(/\A([\da-fA-F]+)\r\n/).first.first len = len_alpha.to_i(16) offset_data = len_alpha.length + 2 # 2 = CRLF = (offset_data+len) str = self[offset_data...] raise 'Too many data in chunk' if + 2 != length str end |
#to_chunk ⇒ Object
converts the string to a chunk (chunked encoding)
4 5 6 |
# File 'lib/icaprb/server/data_structures.rb', line 4 def to_chunk length.to_s(16) + "\r\n" + self + "\r\n" end |