Class: Block::FieldFormat
- Inherits:
-
Object
- Object
- Block::FieldFormat
- Defined in:
- lib/zip64/structures.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #encode(object, value) ⇒ Object
-
#initialize(type, name, options = {}) ⇒ FieldFormat
constructor
A new instance of FieldFormat.
Constructor Details
#initialize(type, name, options = {}) ⇒ FieldFormat
Returns a new instance of FieldFormat.
17 18 19 20 21 22 23 24 |
# File 'lib/zip64/structures.rb', line 17 def initialize(type, name, = {}) if .is_a?(Hash) else val, = , {} [:default] = val end @type, @name, @options = type, name, end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/zip64/structures.rb', line 16 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/zip64/structures.rb', line 16 def type @type end |
Class Method Details
.from(line) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/zip64/structures.rb', line 5 def self.from(line) case line when Array new(*line) when self line else raise "#{line.inspect} is not a valid field" end end |
Instance Method Details
#encode(object, value) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/zip64/structures.rb', line 26 def encode(object, value) val = value || @options[:default] [val].pack(@type).zip64_force_encoding("ASCII-8BIT") rescue raise "#{value.inspect} (#{val.inspect}?) is not a valid type for #{self.inspect}" end |