Class: Resilience::Attribute
- Inherits:
-
Object
- Object
- Resilience::Attribute
show all
- Includes:
- OnImage
- Defined in:
- lib/resilience/attribute.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from OnImage
#image, image, included, restore_pos, #restore_pos, store_pos, #store_pos
Constructor Details
#initialize(args = {}) ⇒ Attribute
Returns a new instance of Attribute.
12
13
14
15
|
# File 'lib/resilience/attribute.rb', line 12
def initialize(args={})
@pos = args[:pos]
@bytes = args[:bytes]
end
|
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
10
11
12
|
# File 'lib/resilience/attribute.rb', line 10
def bytes
@bytes
end
|
#pos ⇒ Object
Returns the value of attribute pos.
9
10
11
|
# File 'lib/resilience/attribute.rb', line 9
def pos
@pos
end
|
Class Method Details
.read ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/resilience/attribute.rb', line 21
def self.read
pos = image.pos
packed = image.read(4)
return new if packed.nil?
attr_len = packed.unpack('L').first
return new if attr_len == 0
image.seek pos
value = image.read(attr_len)
new(:pos => pos, :bytes => value)
end
|
Instance Method Details
#[](key) ⇒ Object
37
38
39
|
# File 'lib/resilience/attribute.rb', line 37
def [](key)
return bytes[key]
end
|
#empty? ⇒ Boolean
17
18
19
|
# File 'lib/resilience/attribute.rb', line 17
def empty?
bytes.nil? || bytes.empty?
end
|
#to_s ⇒ Object
41
42
43
|
# File 'lib/resilience/attribute.rb', line 41
def to_s
bytes.collect { |a| a.to_s(16) }.join(' ')
end
|
#unpack(format) ⇒ Object
33
34
35
|
# File 'lib/resilience/attribute.rb', line 33
def unpack(format)
bytes.unpack(format)
end
|