Class: ThinpXML::Builder
- Inherits:
-
Object
- Object
- ThinpXML::Builder
- Defined in:
- lib/thinp_xml/thinp/builder.rb
Instance Attribute Summary collapse
-
#block_size ⇒ Object
Returns the value of attribute block_size.
-
#nr_mappings ⇒ Object
Returns the value of attribute nr_mappings.
-
#nr_thins ⇒ Object
Returns the value of attribute nr_thins.
-
#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
Returns a new instance of Builder.
9 10 11 12 13 14 |
# File 'lib/thinp_xml/thinp/builder.rb', line 9 def initialize @uuid = '' @nr_thins = 0 @nr_mappings = 0 @block_size = 128 end |
Instance Attribute Details
#block_size ⇒ Object
Returns the value of attribute block_size.
7 8 9 |
# File 'lib/thinp_xml/thinp/builder.rb', line 7 def block_size @block_size end |
#nr_mappings ⇒ Object
Returns the value of attribute nr_mappings.
7 8 9 |
# File 'lib/thinp_xml/thinp/builder.rb', line 7 def nr_mappings @nr_mappings end |
#nr_thins ⇒ Object
Returns the value of attribute nr_thins.
7 8 9 |
# File 'lib/thinp_xml/thinp/builder.rb', line 7 def nr_thins @nr_thins end |
#uuid ⇒ Object
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/thinp_xml/thinp/builder.rb', line 7 def uuid @uuid end |
Instance Method Details
#generate ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/thinp_xml/thinp/builder.rb', line 16 def generate nr_thins = @nr_thins.to_i mapping_counts = (0..nr_thins - 1).map {|n| @nr_mappings.to_i} nr_data_blocks = mapping_counts.inject(0) {|n, tot| n + tot} superblock = Superblock.new(@uuid, 0, 1, @block_size, nr_data_blocks) devices = Array.new offset = 0 0.upto(nr_thins - 1) do |dev| mappings = Array.new nr_mappings = mapping_counts[dev] if nr_mappings > 0 mappings << Mapping.new(0, offset, nr_mappings, 1) offset += nr_mappings end devices << Device.new(dev, nr_mappings, 0, 0, 0, mappings) end Metadata.new(superblock, devices) end |