class PIM::ValueFilter
Constants
- TYPES
Public Class Methods
create(value, types: TYPES)
click to toggle source
# File pim.rb, line 10896 def self.create value, types: TYPES if PIM.is_hash?(value) value, type = value[:value], value[:type] end return nil if value.nil? if type.nil? if types.include?(:array) && PIM.is_array?(value) type = :array elsif types.include?(:boolean) && PIM.is_boolean?(value) type = :boolean elsif types.include?(:regexp) && PIM.is_regexp?(value) type = :regexp elsif types.include?(:template) && /\$\{.*\}/.match?(value.to_s) type = :template else type = :string end end type = type.to_sym raise "#{self.name} type '#{type}' is not valid" unless types.include?(type) value = Array(value.to_s) if type == :array and !PIM.is_array?(value) value = to_boolean(value) if type == :boolean and !PIM.is_boolean?(value) value = Regexp.new(value.to_s) if type == :regexp and !PIM.is_regexp?(value) value = value.to_s if (type == :string or type == :template) and !PIM.is_string?(value) self.new(value: value, type: type) end
Public Instance Methods
as_json()
click to toggle source
# File pim.rb, line 10946 def as_json { value: value, type: type.to_s.upcase } end
matches?(match_value)
click to toggle source
# File pim.rb, line 10930 def matches? match_value case type when :array return self[:value].include?(match_value) when :boolean return self[:value] when :regexp return self[:value].match?(match_value) when :string return self[:value] == match_value when :template # NOTE: We cannot evaluate a JEXL template! end return nil end
to_json(*args)
click to toggle source
# File pim.rb, line 10953 def to_json *args as_json.to_json(*args) end