Class: MesaReader::MesaProfileIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/mesa_reader.rb

Overview

MesaProfileIndex class provides easy access to the data in a mesa profile index file. It is meant primarily as a helper class to the MesaLogDir class but can stand on its own.

EXAMPLES:

>>> include MesaReader >>> index = MesaProfileIndex.new(‘~/mesa/star/work/LOGS/profiles.index’) >>> index.model_numbers # => Sorted Dvector of model numbers that have

available profiles

>>> index.profile_numbers # => Dvector of profile numbers ordered by model

number

>>> index.have_profile_with_model_number?(num) # => true if there is a

profile corresponding to model number number. false otherwise

>>> index.have_profile_with_profile_number?(num) # => true if there is a

profile with profile number num

>>> index.profile_with_model_number(num) # => profile number (integer) that

corresponds to model number num. If there is none, returns nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ MesaProfileIndex

Returns a new instance of MesaProfileIndex.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/mesa_reader.rb', line 194

def initialize(filename)
  @model_numbers = Dobjects::Dvector.new
  @priorities = Dobjects::Dvector.new
  @profile_numbers = Dobjects::Dvector.new
  data_array = [model_numbers, priorities, profile_numbers]
  Dobjects::Dvector.read(filename, data_array, 2)
  @model_number_hash = {}
  model_numbers.each_with_index do |num, i|
    @model_number_hash[num.to_i] = profile_numbers[i].to_i
  end
  @profile_number_hash = model_number_hash.invert
  @profile_numbers.sort! do |num1, num2|
    profile_number_hash[num1.to_i] <=> profile_number_hash[num2.to_i]
  end
  @model_numbers.sort!
end

Instance Attribute Details

#model_number_hashObject (readonly)

Returns the value of attribute model_number_hash.



192
193
194
# File 'lib/mesa_reader.rb', line 192

def model_number_hash
  @model_number_hash
end

#model_numbersObject (readonly)

Returns the value of attribute model_numbers.



192
193
194
# File 'lib/mesa_reader.rb', line 192

def model_numbers
  @model_numbers
end

#prioritiesObject (readonly)

Returns the value of attribute priorities.



192
193
194
# File 'lib/mesa_reader.rb', line 192

def priorities
  @priorities
end

#profile_number_hashObject (readonly)

Returns the value of attribute profile_number_hash.



192
193
194
# File 'lib/mesa_reader.rb', line 192

def profile_number_hash
  @profile_number_hash
end

#profile_numbersObject (readonly)

Returns the value of attribute profile_numbers.



192
193
194
# File 'lib/mesa_reader.rb', line 192

def profile_numbers
  @profile_numbers
end

Instance Method Details

#have_profile_with_model_number?(model_number) ⇒ Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/mesa_reader.rb', line 210

def have_profile_with_model_number?(model_number)
  model_numbers.include?(model_number)
end

#have_profile_with_profile_number?(profile_number) ⇒ Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/mesa_reader.rb', line 213

def have_profile_with_profile_number?(profile_number)
  profile_numbers.include?(profile_number)
end

#profile_with_model_number(model_number) ⇒ Object



216
217
218
# File 'lib/mesa_reader.rb', line 216

def profile_with_model_number(model_number)
  model_number_hash[model_number]
end