Module: Train::Platforms

Defined in:
lib/train/platforms.rb,
lib/train/platforms/common.rb,
lib/train/platforms/detect.rb,
lib/train/platforms/family.rb,
lib/train/platforms/platform.rb

Defined Under Namespace

Modules: Common, Detect Classes: Family, Platform

Class Method Summary collapse

Class Method Details

.__resetObject

Clear all platform settings. Only used for testing.



29
30
31
32
# File 'lib/train/platforms.rb', line 29

def __reset
  @list = {}
  @families = {}
end

.exportObject



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/train/platforms.rb', line 91

def self.export
  export = []
  list.each do |name, platform|
    platform.find_family_hierarchy
    export << {
      name: name,
      families: platform.family_hierarchy,
    }
  end
  export.sort_by { |platform| platform[:name] }
end

.familiesHash

Retrieve the current family list

Returns:

  • (Hash)

    map with family names and their objects



24
25
26
# File 'lib/train/platforms.rb', line 24

def families
  @families ||= {}
end

.family(name, condition = {}) ⇒ Object

Create or update a family

Returns:

  • Train::Platforms::Family



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/train/platforms.rb', line 53

def self.family(name, condition = {})
  # Check the families to see if one is already created
  family = families[name]
  unless family.nil?
    # Pass the condition incase we are adding a family relationship
    family.condition = condition unless condition.nil?
    return family
  end

  Train::Platforms::Family.new(name, condition)
end

.listHash

Retrieve the current platform list

Returns:

  • (Hash)

    map with platform names and their objects



17
18
19
# File 'lib/train/platforms.rb', line 17

def list
  @list ||= {}
end

.list_allObject

List all platforms and families in a readable output



75
76
77
78
79
80
81
# File 'lib/train/platforms.rb', line 75

def self.list_all
  top_platforms = self.top_platforms
  top_platforms.each_value do |platform|
    puts platform.title
    print_children(platform) if defined?(platform.children)
  end
end

.name(name, condition = {}) ⇒ Object

Create or update a platform

Returns:

  • Train::Platform



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/train/platforms.rb', line 38

def self.name(name, condition = {})
  # Check the list to see if one is already created
  plat = list[name]
  unless plat.nil?
    # Pass the condition incase we are adding a family relationship
    plat.condition = condition unless condition.nil?
    return plat
  end

  Train::Platforms::Platform.new(name, condition)
end


83
84
85
86
87
88
89
# File 'lib/train/platforms.rb', line 83

def self.print_children(parent, pad = 2)
  parent.children.each do |key, value|
    obj = key
    puts "#{' ' * pad}-> #{obj.title}#{value unless value.empty?}"
    print_children(obj, pad + 2) if defined?(obj.children) && !obj.children.nil?
  end
end

.top_platformsHash

Find the families or top level platforms

Returns:

  • (Hash)

    with top level family and platforms



68
69
70
71
72
# File 'lib/train/platforms.rb', line 68

def self.top_platforms
  top_platforms = list.select { |_key, value| value.families.empty? }
  top_platforms.merge!(families.select { |_key, value| value.families.empty? })
  top_platforms
end