Class: Puppet::Pops::Evaluator::CompareOperator

Inherits:
Object
  • Object
show all
Includes:
Runtime3Support, Utils
Defined in:
lib/puppet/pops/evaluator/compare_operator.rb

Overview

Compares the puppet DSL way

==Equality All string vs. numeric equalities check for numeric equality first, then string equality Arrays are equal to arrays if they have the same length, and each element #equals Hashes are equal to hashes if they have the same size and keys and values #equals. All other objects are equal if they are ruby #== equal

Constant Summary

Constants included from Runtime3Support

Runtime3Support::CLASS_STRING, Runtime3Support::NAME_SPACE_SEPARATOR

Instance Method Summary collapse

Methods included from Runtime3Support

#add_relationship, #call_function, #capitalize_qualified_name, #coerce_numeric, #convert, #convert_Array, #convert_Hash, #convert_NilClass, #convert_Object, #convert_PAnyType, #convert_PCatalogEntryType, #convert_Regexp, #convert_String, #convert_Symbol, #create_local_scope_from, #create_match_scope_from, #create_resource_defaults, #create_resource_overrides, #create_resource_parameter, #create_resources, #fail, #find_resource, #get_resource_parameter_value, #get_scope_nesting_level, #get_variable_value, #is_boolean?, #is_parameter_of_resource?, #is_true?, #optionally_fail, #resource_to_ptype, #set_match_data, #set_scope_nesting_level, #set_variable, #variable_bound?, #variable_exists?

Methods included from Utils

find_adapter, find_closest_positioned, is_absolute?, is_numeric?, name_to_segments, relativize_name, to_n, to_n_with_radix

Constructor Details

#initializeCompareOperator

Returns a new instance of CompareOperator.



17
18
19
20
21
22
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 17

def initialize
  @@equals_visitor  ||= Puppet::Pops::Visitor.new(self, "equals", 1, 1)
  @@compare_visitor ||= Puppet::Pops::Visitor.new(self, "cmp", 1, 1)
  @@include_visitor ||= Puppet::Pops::Visitor.new(self, "include", 2, 2)
  @type_calculator = Puppet::Pops::Types::TypeCalculator.new()
end

Instance Method Details

#compare(a, b) ⇒ Object

Performs a comparison of a and b, and return > 0 if a is bigger, 0 if equal, and < 0 if b is bigger. Comparison of String vs. Numeric always compares using numeric.



30
31
32
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 30

def compare(a, b)
  @@compare_visitor.visit_this_1(self, a, b)
end

#equals(a, b) ⇒ Object



24
25
26
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 24

def equals (a, b)
  @@equals_visitor.visit_this_1(self, a, b)
end

#include?(a, b, scope) ⇒ Boolean

Answers is b included in a

Returns:

  • (Boolean)


35
36
37
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 35

def include?(a, b, scope)
  @@include_visitor.visit_this_2(self, a, b, scope)
end