Class: Resilience::FSDir::Record

Inherits:
Object
  • Object
show all
Includes:
OnImage
Defined in:
lib/resilience/fs_dir/record.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(attribute) ⇒ Record

Returns a new instance of Record.



12
13
14
# File 'lib/resilience/fs_dir/record.rb', line 12

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



10
11
12
# File 'lib/resilience/fs_dir/record.rb', line 10

def attribute
  @attribute
end

Class Method Details

.readObject



16
17
18
# File 'lib/resilience/fs_dir/record.rb', line 16

def self.read
  new(Attribute.read)
end

Instance Method Details

#boundriesObject



31
32
33
34
# File 'lib/resilience/fs_dir/record.rb', line 31

def boundries
  calc_boundries
  [@key_offset, @key_length, @value_offset, @value_length]
end

#calc_boundriesObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/resilience/fs_dir/record.rb', line 20

def calc_boundries
  return if @boundries_set
  @boundries_set = true
  
  header         = attribute.unpack('S*')
  @key_offset    = header[2]
  @key_length    = header[3]
  @value_offset  = header[5]
  @value_length  = header[6]
end

#calc_flagsObject



36
37
38
39
40
41
# File 'lib/resilience/fs_dir/record.rb', line 36

def calc_flags
  return if @flags_set
  @flags_set = true
  
  @flags = attribute.unpack('S*')[4]
end

#flagsObject



43
44
45
46
# File 'lib/resilience/fs_dir/record.rb', line 43

def flags
  calc_flags
  @flags
end

#keyObject



48
49
50
51
# File 'lib/resilience/fs_dir/record.rb', line 48

def key
  ko, kl, vo, vl = boundries
  attribute.unpack('C*')[ko...ko+kl].pack('C*')
end

#valueObject



53
54
55
56
# File 'lib/resilience/fs_dir/record.rb', line 53

def value
  ko, kl, vo, vl = boundries
  attribute.unpack('C*')[vo..-1].pack('C*')
end