Class: MasterView::Analyzer::Builder

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/masterview/analyzer.rb

Overview

builder class facilitates the hash_check and building process by monitoring if all parts of a file have been requested, if not when a higher index part is requested all the other previous parts will be sent along as well, this is necessary for cases where a file doesn’t have as many internal parts or none at all. This way the hash and all the parts of the file will still be there if layout has two parts and only last part -1 is requested, this builder will give back part 0 and part 1 if layout would have had three parts then it would have given back all three. if a part does not exist then it will come back as empty string, same for an index out of bounds

Constant Summary

Constants included from Common

Common::ImportToNonImportDir, Common::NonImportToImportDir

Instance Method Summary collapse

Methods included from Common

#calc_hash, #convert_import_to_non_import_dirs, #convert_non_import_to_import_dirs, #src_hash

Constructor Details

#initialize(content_hash) ⇒ Builder

Returns a new instance of Builder.



104
105
106
107
# File 'lib/masterview/analyzer.rb', line 104

def initialize(content_hash)
  @content_hash = content_hash
  @builder_hash = {} #will contain next index to use
end

Instance Method Details

#data(name, index) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/masterview/analyzer.rb', line 113

def data(name, index)
  content = ''
  content_parts = @content_hash[name]
  content_parts_length = (content_parts) ? content_parts.length : 0
  next_index_to_use = (nind = @builder_hash[name]) ? nind : 0
  next_index_to_use = 0 if (-1 == index) && (next_index_to_use+1 > content_parts_length) # allow -1 to rerequest part as needed (singlefile)
  return '' if content_parts.nil? || (next_index_to_use+1 > content_parts_length)
  highest_index = content_parts.length - 1
  requested_index = (index == -1) ? highest_index : index
  content = content_parts[next_index_to_use..requested_index].collect do |ce|
    (ce.data.gsub( /\s/, '' ).empty?) ? '' : ce.data # if only white space then get rid of it
  end.join
  @builder_hash[name] = requested_index + 1 # store next index to use
  content
end

#hash(name, index) ⇒ Object



109
110
111
# File 'lib/masterview/analyzer.rb', line 109

def hash(name, index)
  src_hash(data(name, index))
end