Class: AbideDevUtils::Ppt::FacterUtils::FactSet
- Inherits:
-
Object
- Object
- AbideDevUtils::Ppt::FacterUtils::FactSet
- Includes:
- DotNumberComparable
- Defined in:
- lib/abide_dev_utils/ppt/facter_utils.rb
Overview
A set of facts for a specific Facter version
Instance Attribute Summary collapse
-
#facter_version ⇒ Object
(also: #number)
readonly
Returns the value of attribute facter_version.
-
#facts ⇒ Object
readonly
Returns the value of attribute facts.
Instance Method Summary collapse
- #dig(*args) ⇒ Object
- #dot_dig(dot_path) ⇒ Object
- #find_by_fact_value_tuple(fact_val_tuple) ⇒ Object
- #find_by_fact_value_tuples(*fact_val_tuples) ⇒ Object
-
#initialize(facter_version) ⇒ FactSet
constructor
A new instance of FactSet.
- #load_facts(fact_file) ⇒ Object
Methods included from DotNumberComparable
#<=>, #number_child_of?, #number_eq, #number_gt, #number_lt, #number_parent_of?
Constructor Details
#initialize(facter_version) ⇒ FactSet
Returns a new instance of FactSet.
17 18 19 20 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 17 def initialize(facter_version) @facter_version = facter_version.to_s @facts = [] end |
Instance Attribute Details
#facter_version ⇒ Object (readonly) Also known as: number
Returns the value of attribute facter_version.
15 16 17 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 15 def facter_version @facter_version end |
#facts ⇒ Object (readonly)
Returns the value of attribute facts.
15 16 17 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 15 def facts @facts end |
Instance Method Details
#dig(*args) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 49 def dig(*args) result = @facts.map { |f| f.dig(*args) } return nil if result.empty? result end |
#dot_dig(dot_path) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 42 def dot_dig(dot_path) result = @facts.map { |f| f.dig(*dot_path.delete_prefix('facts').split('.')) } return nil if result.empty? result end |
#find_by_fact_value_tuple(fact_val_tuple) ⇒ Object
37 38 39 40 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 37 def find_by_fact_value_tuple(fact_val_tuple) fact_name, fact_val = fact_val_tuple @facts.find { |f| f.dig(*fact_name.delete_prefix('facts').split('.')) == fact_val } end |
#find_by_fact_value_tuples(*fact_val_tuples) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 27 def find_by_fact_value_tuples(*fact_val_tuples) facts.each do |f| results = fact_val_tuples.each_with_object([]) do |fvt, ary| ary << true if f.dig(*fvt[0].delete_prefix('facts').split('.')) == fvt[1] end return f if results.size == fact_val_tuples.size end nil end |
#load_facts(fact_file) ⇒ Object
23 24 25 |
# File 'lib/abide_dev_utils/ppt/facter_utils.rb', line 23 def load_facts(fact_file) @facts << JSON.parse(File.read(fact_file)) end |