Class: Block::FieldFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/zip64/structures.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
	if options.is_a?(Hash)
	else
		val, options = options, {}
		options[:default] = val
	end
	@type, @name, @options = type, name, options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/zip64/structures.rb', line 16

def name
  @name
end

#typeObject (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