Module: Packable::Extensions::String

Defined in:
lib/packable/extensions/string.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/packable/extensions/string.rb', line 7

def self.included(base)
  base.class_eval do
    include Packable
    extend ClassMethods
    alias_method_chain :unpack, :long_form
    packers.set :merge_all, :fill => " "
  end
end

Instance Method Details

#unpack_with_long_form(*arg) ⇒ Object



21
22
23
24
25
26
# File 'lib/packable/extensions/string.rb', line 21

def unpack_with_long_form(*arg)
  return unpack_without_long_form(*arg) if arg.first.is_a? String
  StringIO.new(self).packed.read(*arg)
rescue EOFError
  nil
end

#write_packed(io, options) ⇒ Object



16
17
18
19
# File 'lib/packable/extensions/string.rb', line 16

def write_packed(io, options)
  return io.write_without_packing(self) unless options[:bytes]
  io.write_without_packing(self[0...options[:bytes]].ljust(options[:bytes], options[:fill] || "\000"))
end