Class: EraXML::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/thinp_xml/era/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder



9
10
11
12
13
14
15
# File 'lib/thinp_xml/era/builder.rb', line 9

def initialize
  @uuid = ''
  @block_size = 128
  @nr_blocks = 0
  @current_era = 0
  @nr_writesets = 0
end

Instance Attribute Details

#block_sizeObject

Returns the value of attribute block_size.



7
8
9
# File 'lib/thinp_xml/era/builder.rb', line 7

def block_size
  @block_size
end

#current_eraObject

Returns the value of attribute current_era.



7
8
9
# File 'lib/thinp_xml/era/builder.rb', line 7

def current_era
  @current_era
end

#nr_blocksObject

Returns the value of attribute nr_blocks.



7
8
9
# File 'lib/thinp_xml/era/builder.rb', line 7

def nr_blocks
  @nr_blocks
end

#nr_writesetsObject

Returns the value of attribute nr_writesets.



7
8
9
# File 'lib/thinp_xml/era/builder.rb', line 7

def nr_writesets
  @nr_writesets
end

#uuidObject

Returns the value of attribute uuid.



7
8
9
# File 'lib/thinp_xml/era/builder.rb', line 7

def uuid
  @uuid
end

Instance Method Details

#generateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/thinp_xml/era/builder.rb', line 17

def generate
  s = Superblock.new(@uuid, @block_size, @nr_blocks, @current_era)

  if @nr_writesets > @current_era
    raise "can't have more writesets than eras"
  end

  era_array_limit = @current_era - @nr_writesets

  writesets = (0..@nr_writesets - 1).map do |i|
    bits = (0..@nr_blocks - 1).map do |block|
      WritesetBit.new(block, rand(2) == 0 ? false : true)
    end

    Writeset.new(era_array_limit + i, @nr_blocks, bits)
  end

  era_array = (0..@nr_blocks - 1).map do |block|
    if @current_era > 0
      rand(era_array_limit)
    else
      0
    end
  end

  .new(s, writesets, era_array)
end