Class: AbideDevUtils::CEM::Mapping::MapData

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/cem/mapping/mapper.rb

Overview

Represents a single map data file

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ MapData

Returns a new instance of MapData.



19
20
21
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 19

def initialize(data)
  @raw_data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 23

def method_missing(meth, *args, &block)
  if data.respond_to?(meth)
    data.send(meth, *args, &block)
  else
    super
  end
end

Instance Method Details

#benchmarkObject



75
76
77
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 75

def benchmark
  @raw_data[top_key]['benchmark']
end

#find(identifier, level: nil, profile: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 35

def find(identifier, level: nil, profile: nil)
  levels.each do |lvl|
    next unless level.nil? || lvl != level

    data[lvl].each do |prof, prof_data|
      if prof_data.respond_to?(:keys)
        next unless profile.nil? || prof != profile

        return prof_data[identifier] if prof_data.key?(identifier)
      elsif prof == identifier
        return prof_data
      end
    end
  end
end

#frameworkObject



67
68
69
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 67

def framework
  top_key_parts[2]
end

#get(identifier, level: nil, profile: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 51

def get(identifier, level: nil, profile: nil)
  raise "Invalid level: #{level}" unless profile.nil? || levels.include?(level)
  raise "Invalid profile: #{profile}" unless profile.nil? || profiles.include?(profile)
  return find(identifier, level: level, profile: profile) if level.nil? || profile.nil?

  begin
    data.dig(level, profile, identifier)
  rescue TypeError
    data.dig(level, identifier)
  end
end

#levelsObject



83
84
85
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 83

def levels
  levels_and_profiles[0]
end

#levels_and_profilesObject



79
80
81
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 79

def levels_and_profiles
  @levels_and_profiles ||= find_levels_and_profiles
end

#module_nameObject



63
64
65
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 63

def module_name
  top_key_parts[0]
end

#profilesObject



87
88
89
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 87

def profiles
  levels_and_profiles[1]
end

#respond_to_missing?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 31

def respond_to_missing?(meth, include_private = false)
  data.respond_to?(meth) || super
end

#top_keyObject



91
92
93
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 91

def top_key
  @top_key ||= @raw_data.keys.first
end

#typeObject



71
72
73
# File 'lib/abide_dev_utils/cem/mapping/mapper.rb', line 71

def type
  top_key_parts[3]
end