Module: Rubyzen::Providers::CollectionFilterProvider

Overview

Provides name-based filtering methods for collections.

Instance Method Summary collapse

Instance Method Details

#with_name(name) ⇒ self

Returns filtered collection containing only items with the given name.

Parameters:

  • name (String)

    the exact name to match

Returns:

  • (self)

    filtered collection containing only items with the given name



7
8
9
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 7

def with_name(name)
  filter { |item| item.name == name }
end

#with_name_ending_with(suffix) ⇒ self

Returns filtered collection of items whose names end with the suffix.

Parameters:

  • suffix (String)

    the suffix to match against item names

Returns:

  • (self)

    filtered collection of items whose names end with the suffix



13
14
15
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 13

def with_name_ending_with(suffix)
  filter { |item| item.name&.end_with?(suffix) }
end

#with_name_including(substring, case_sensitive: true) ⇒ self

Returns filtered collection of items whose names contain the substring.

Parameters:

  • substring (String)

    the substring to search for in item names

  • case_sensitive (Boolean) (defaults to: true)

    whether the match is case-sensitive (default: true)

Returns:

  • (self)

    filtered collection of items whose names contain the substring



26
27
28
29
30
31
32
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 26

def with_name_including(substring, case_sensitive: true)
  if case_sensitive
    filter { |item| item.name&.include?(substring) }
  else
    filter { |item| item.name&.downcase&.include?(substring.downcase) }
  end
end

#with_name_starting_with(prefix) ⇒ self

Returns filtered collection of items whose names start with the prefix.

Parameters:

  • prefix (String)

    the prefix to match against item names

Returns:

  • (self)

    filtered collection of items whose names start with the prefix



19
20
21
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 19

def with_name_starting_with(prefix)
  filter { |item| item.name&.start_with?(prefix) }
end

#without_name(*names) ⇒ self

Returns filtered collection excluding items with any of the given names.

Parameters:

  • names (Array<String>)

    names to exclude

Returns:

  • (self)

    filtered collection excluding items with any of the given names



36
37
38
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 36

def without_name(*names)
  filter { |item| !names.include?(item.name) }
end

#without_name_ending_with(suffix) ⇒ self

Returns filtered collection excluding items whose names end with the suffix.

Parameters:

  • suffix (String)

    the suffix to exclude

Returns:

  • (self)

    filtered collection excluding items whose names end with the suffix



42
43
44
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 42

def without_name_ending_with(suffix)
  filter { |item| !item.name&.end_with?(suffix) }
end

#without_name_including(substring, case_sensitive: true) ⇒ self

Returns filtered collection excluding items whose names contain the substring.

Parameters:

  • substring (String)

    the substring to exclude

  • case_sensitive (Boolean) (defaults to: true)

    whether the match is case-sensitive (default: true)

Returns:

  • (self)

    filtered collection excluding items whose names contain the substring



55
56
57
58
59
60
61
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 55

def without_name_including(substring, case_sensitive: true)
  if case_sensitive
    filter { |item| !item.name&.include?(substring) }
  else
    filter { |item| !item.name&.downcase&.include?(substring.downcase) }
  end
end

#without_name_starting_with(prefix) ⇒ self

Returns filtered collection excluding items whose names start with the prefix.

Parameters:

  • prefix (String)

    the prefix to exclude

Returns:

  • (self)

    filtered collection excluding items whose names start with the prefix



48
49
50
# File 'lib/rubyzen/providers/collection_filter_provider.rb', line 48

def without_name_starting_with(prefix)
  filter { |item| !item.name&.start_with?(prefix) }
end