Class: Udb::ParamCondition

Inherits:
Condition show all
Extended by:
T::Sig
Defined in:
lib/udb/condition.rb

Instance Method Summary collapse

Constructor Details

#initialize(yaml, cfg_arch)

Parameters:



1589
1590
1591
# File 'lib/udb/condition.rb', line 1589

def initialize(yaml, cfg_arch)
  super(yaml, cfg_arch)
end

Instance Method Details

#to_logic_tree_internalLogicNode

Returns:



1638
1639
1640
# File 'lib/udb/condition.rb', line 1638

def to_logic_tree_internal
  @logic_tree ||= to_param_logic_tree_helper(@yaml)
end

#to_param_logic_tree_helper(yaml) ⇒ LogicNode

Parameters:

  • yaml (true, false, Hash{String => T.untyped})

Returns:



1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
# File 'lib/udb/condition.rb', line 1599

def to_param_logic_tree_helper(yaml)
  if yaml == true
    LogicNode::True
  elsif yaml == false
    LogicNode::False
  elsif yaml.key?("name")
    LogicNode.new(LogicNodeType::Term, [ParameterTerm.new(yaml)])
  elsif yaml.key?("allOf")
    LogicNode.new(LogicNodeType::And, yaml.fetch("allOf").map { |y| to_param_logic_tree_helper(y) })
  elsif yaml.key?("anyOf")
    LogicNode.new(LogicNodeType::Or, yaml.fetch("anyOf").map { |y| to_param_logic_tree_helper(y) })
  elsif yaml.key?("oneOf")
    LogicNode.new(LogicNodeType::Xor, yaml.fetch("oneOf").map { |y| to_param_logic_tree_helper(y) })
  elsif yaml.key?("noneOf")
    LogicNode.new(LogicNodeType::Not,
      [
        LogicNode.new(LogicNodeType::Or, yaml.fetch("noneOf").map { |y| to_param_logic_tree_helper(y) })
      ]
    )
  elsif yaml.key?("not")
    LogicNode.new(LogicNodeType::Not, [to_param_logic_tree_helper(yaml.fetch("not"))])
  elsif yaml.key?("if")
    LogicNode.new(LogicNodeType::If,
      [
        Condition.new(yaml.fetch("if"), @cfg_arch).to_logic_tree_internal,
        to_param_logic_tree_helper(yaml.fetch("then"))
      ]
    )
  elsif yaml.key?("param")
    to_param_logic_tree_helper(yaml.fetch("param"))
  else
    raise "unexpected key #{yaml.keys}"
  end
end