Class: MiniTarball::HeaderFields
- Inherits:
-
Object
- Object
- MiniTarball::HeaderFields
- Defined in:
- lib/mini_tarball/header_fields.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(header) ⇒ HeaderFields
constructor
A new instance of HeaderFields.
-
#set_value(name, value) ⇒ Object
:reek:DuplicateMethodCall.
- #to_binary ⇒ Object
- #update_checksum ⇒ Object
Constructor Details
#initialize(header) ⇒ HeaderFields
Returns a new instance of HeaderFields.
9 10 11 12 |
# File 'lib/mini_tarball/header_fields.rb', line 9 def initialize(header) @header = header @values_by_field = {} end |
Class Method Details
Instance Method Details
#set_value(name, value) ⇒ Object
:reek:DuplicateMethodCall
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mini_tarball/header_fields.rb', line 25 def set_value(name, value) field = Header::FIELDS[name] case field[:type] when :number @values_by_field[name] = HeaderFormatter.format_number(value, field[:length]) when :mode @values_by_field[name] = HeaderFormatter.(value, field[:length]) when :checksum @values_by_field[name] = HeaderFormatter.format_checksum(value) else @values_by_field[name] = value end end |
#to_binary ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/mini_tarball/header_fields.rb', line 14 def to_binary Header::FIELDS.each_key do |name| value = @header.value_of(name) set_value(name, value) end update_checksum HeaderFormatter.zero_pad(encode_fields) end |
#update_checksum ⇒ Object
40 41 42 43 |
# File 'lib/mini_tarball/header_fields.rb', line 40 def update_checksum checksum = encode_fields.unpack("C*").sum set_value(:checksum, checksum) end |