Class: EraXML::Builder
- Inherits:
-
Object
- Object
- EraXML::Builder
- Defined in:
- lib/thinp_xml/era/builder.rb
Instance Attribute Summary collapse
-
#block_size ⇒ Object
Returns the value of attribute block_size.
-
#current_era ⇒ Object
Returns the value of attribute current_era.
-
#nr_blocks ⇒ Object
Returns the value of attribute nr_blocks.
-
#nr_writesets ⇒ Object
Returns the value of attribute nr_writesets.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize ⇒ Builder
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_size ⇒ Object
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_era ⇒ Object
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_blocks ⇒ Object
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_writesets ⇒ Object
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 |
#uuid ⇒ Object
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
#generate ⇒ Object
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 Metadata.new(s, writesets, era_array) end |