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
-
.__reset ⇒ Object
Clear all platform settings.
- .export ⇒ Object
-
.families ⇒ Hash
Retrieve the current family list.
-
.family(name, condition = {}) ⇒ Object
Create or update a family.
-
.list ⇒ Hash
Retrieve the current platform list.
-
.list_all ⇒ Object
List all platforms and families in a readable output.
-
.name(name, condition = {}) ⇒ Object
Create or update a platform.
- .print_children(parent, pad = 2) ⇒ Object
-
.top_platforms ⇒ Hash
Find the families or top level platforms.
Class Method Details
.__reset ⇒ Object
Clear all platform settings. Only used for testing.
26 27 28 29 |
# File 'lib/train/platforms.rb', line 26 def self.__reset @list = {} @families = {} end |
.export ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/train/platforms.rb', line 89 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 |
.families ⇒ Hash
Retrieve the current family list
21 22 23 |
# File 'lib/train/platforms.rb', line 21 def self.families @families ||= {} end |
.family(name, condition = {}) ⇒ Object
Create or update a family
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/train/platforms.rb', line 50 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 |
.list ⇒ Hash
Retrieve the current platform list
14 15 16 |
# File 'lib/train/platforms.rb', line 14 def self.list @list ||= {} end |
.list_all ⇒ Object
List all platforms and families in a readable output
73 74 75 76 77 78 79 |
# File 'lib/train/platforms.rb', line 73 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
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/train/platforms.rb', line 34 def self.name(name, condition = {}) # TODO: refactor this against family. They're stupidly similar # 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 |
.print_children(parent, pad = 2) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/train/platforms.rb', line 81 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_platforms ⇒ Hash
Find the families or top level platforms
65 66 67 68 69 70 |
# File 'lib/train/platforms.rb', line 65 def self.top_platforms empty_list = list.select { |_key, value| value.families.empty? } empty_fams = families.select { |_key, value| value.families.empty? } empty_list.merge empty_fams end |