Module: Rubyzen::Providers::CollectionFilterProvider
- Included in:
- Collections::AttributesCollection, Collections::BlocksCollection, Collections::CallSiteCollection, Collections::ClassesCollection, Collections::ConstantsCollection, Collections::FileCollection, Collections::MacrosCollection, Collections::MethodsCollection, Collections::ModulesCollection, Collections::ParametersCollection, Collections::RequiresCollection
- Defined in:
- lib/rubyzen/providers/collection_filter_provider.rb
Overview
Provides name-based filtering methods for collections.
Instance Method Summary collapse
-
#with_name(name) ⇒ self
Filtered collection containing only items with the given name.
-
#with_name_ending_with(suffix) ⇒ self
Filtered collection of items whose names end with the suffix.
-
#with_name_including(substring, case_sensitive: true) ⇒ self
Filtered collection of items whose names contain the substring.
-
#with_name_starting_with(prefix) ⇒ self
Filtered collection of items whose names start with the prefix.
-
#without_name(*names) ⇒ self
Filtered collection excluding items with any of the given names.
-
#without_name_ending_with(suffix) ⇒ self
Filtered collection excluding items whose names end with the suffix.
-
#without_name_including(substring, case_sensitive: true) ⇒ self
Filtered collection excluding items whose names contain the substring.
-
#without_name_starting_with(prefix) ⇒ self
Filtered collection excluding items whose names start with the prefix.
Instance Method Details
#with_name(name) ⇒ self
Returns 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.
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.
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.
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.
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.
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.
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.
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 |