Class: Array

Inherits:
Object show all
Includes:
JamfRubyExtensions::Array::Predicates, JamfRubyExtensions::Array::Utils, RubyDig
Defined in:
lib/jamf/ruby_extensions/dig.rb,
lib/jss/compatibility.rb,
lib/jamf/compatibility.rb,
lib/jss/ruby_extensions/array.rb,
lib/jamf/ruby_extensions/array.rb

Overview

an array

Instance Method Summary collapse

Instance Method Details

#dig(key, *rest) ⇒ Object Originally defined in module RubyDig

#j_ci_fetch(somestring) ⇒ String? Originally defined in module JamfRubyExtensions::Array::Utils

Fetch a string from an Array case-insensitively, e.g. if my_array contains 'thrasher',

my_array.j_ci_fetch('ThRashEr')

will return 'thrasher'

returns nil if no match

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (String, nil)

    The matching string as it exists in the Array, nil if it doesn't exist

#j_ci_include?(somestring) ⇒ Boolean Originally defined in module JamfRubyExtensions::Array::Utils

case-insensitive version of include?

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (Boolean)

#j_ci_include_string?(somestring) ⇒ Boolean Originally defined in module JamfRubyExtensions::Array::Predicates

A case-insensitive version of #include? for Arrays of Strings.

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (Boolean)

    Does the Array contain the String, ignoring case?

#jss_ci_fetch_string(somestring) ⇒ String?

Fetch a string from an Array of Strings case-insensitively, e.g. my_array.jss_ci_fetch_string('ThRashEer') will return 'thrasher' or nil if no match

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (String, nil)

    The matching string as it exists in the Array, nil if it doesn't exist



47
48
49
50
# File 'lib/jss/ruby_extensions/array.rb', line 47

def jss_ci_fetch_string(somestring)
  idx = index { |s| s.to_s.casecmp(somestring).zero? }
  idx ? self[idx] : nil
end

#jss_ci_include_string?(somestring) ⇒ Boolean

A case-insensitive version of #include? for Arrays of Strings.

Parameters:

  • somestring (String)

    the String to search for

Returns:

  • (Boolean)

    Does the Array contain the String, ignoring case?



35
36
37
# File 'lib/jss/ruby_extensions/array.rb', line 35

def jss_ci_include_string?(somestring)
  any? { |s| s.to_s.casecmp(somestring).zero? }
end