class Object

Public Instance Methods

not_truthy?(string) click to toggle source
# File lib/cfn-model/util/truthy.rb, line 9
def not_truthy?(string)
  string.nil? || string.to_s.casecmp('false').zero?
end
truthy?(string) click to toggle source

Checks a string for truthiness. Any cased 'true' will evaluate to a true boolean. Any other string _at all_ results in false.

# File lib/cfn-model/util/truthy.rb, line 5
def truthy?(string)
  string.to_s.casecmp('true').zero?
end
wildcard_back(input_string, results = [], prepend = '') click to toggle source
# File lib/cfn-model/util/wildcard_patterns.rb, line 25
def wildcard_back(input_string, results = [], prepend = '')
  return results if input_string.empty?

  results << "#{prepend}#{input_string}*"
  wildcard_back(input_string.chop, results, prepend)
end
wildcard_front(input_string, results = []) click to toggle source
# File lib/cfn-model/util/wildcard_patterns.rb, line 32
def wildcard_front(input_string, results = [])
  return results if input_string.empty?

  results << "*#{input_string}"
  wildcard_front(input_string[1..-1], results)
end
wildcard_front_back(input_string, results = []) click to toggle source
# File lib/cfn-model/util/wildcard_patterns.rb, line 39
def wildcard_front_back(input_string, results = [])
  return results if input_string.empty?

  results += wildcard_back(input_string, [], '*')
  wildcard_front_back(input_string[1..-1], results)
end
wildcard_patterns(input, pattern_types: %w[front back both]) click to toggle source

Create array of wildcard patterns for a given input string

# File lib/cfn-model/util/wildcard_patterns.rb, line 5
def wildcard_patterns(input, pattern_types: %w[front back both])
  input_string = input.to_s
  results = [input_string]
  pattern_types.each do |pattern_type|
    case pattern_type
    when 'front'
      results += wildcard_front(input_string)
    when 'back'
      results += wildcard_back(input_string)
    when 'both'
      results += wildcard_front_back(input_string)
    else
      raise "no pattern of type: #{pattern_type}. Use one or more of: front, back, both"
    end
  end
  results + ['*']
end