class GZippedTar::Tar::Field
Attributes
default[R]
length[R]
name[R]
octal[R]
required[R]
Public Class Methods
new(name, length, options = {})
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 6 def initialize(name, length, options = {}) @name = name @length = length @octal = options[:octal] @required = options[:required] @default = options[:default] end
Public Instance Methods
octal?()
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 14 def octal? octal end
pack()
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 18 def pack return "a" if length == 1 "a#{length}" end
required?()
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 24 def required? required end
to_s(value)
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 28 def to_s(value) return value unless octal? if length == 2 format "%0#{length}o", value else format "%0#{length - 1}o", value end end
translate(value)
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 38 def translate(value) value ||= default return value unless octal? && value.is_a?(String) return value.oct if value[/\A[0-7]*\z/] raise ArgumentError, "#{value.inspect} is not an octal string" end
unpack()
click to toggle source
# File lib/gzipped_tar/tar/field.rb, line 47 def unpack return "A" if length == 1 "A#{length}" end