Class: MicroMicro::Collections::PropertiesCollection
- Inherits:
-
BaseCollection
- Object
- BaseCollection
- MicroMicro::Collections::PropertiesCollection
- Defined in:
- lib/micro_micro/collections/properties_collection.rb
Instance Method Summary collapse
-
#find_by(**args, &block) ⇒ MicroMicro::Property?
Return the first Property from a search.
-
#names ⇒ Array<String>
Retrieve an Array of this collection’s unique Property names.
-
#plain_text_properties ⇒ MicroMicro::Collections::PropertiesCollection
A collection of plain text Propertys parsed from the node.
-
#plain_text_properties? ⇒ Boolean
Does this PropertiesCollection include any plain text Propertys?.
-
#to_h ⇒ Hash{Symbol => Array<String, Hash>}
Return a Hash of this collection’s Propertys as Arrays.
-
#url_properties ⇒ MicroMicro::Collections::PropertiesCollection
A collection of url Propertys parsed from the node.
-
#url_properties? ⇒ Boolean
Does this PropertiesCollection include any url Propertys?.
-
#values ⇒ Array<String, Hash>
Return an Array of this collection’s unique Property values.
-
#where(**args) {|property| ... } ⇒ MicroMicro::Collections::PropertiesCollection
Search this collection for Propertys matching the given conditions.
Methods inherited from BaseCollection
Constructor Details
This class inherits a constructor from MicroMicro::Collections::BaseCollection
Instance Method Details
#find_by(**args, &block) ⇒ MicroMicro::Property?
Return the first Property from a search.
29 30 31 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 29 def find_by(**args, &block) where(**args, &block).first end |
#names ⇒ Array<String>
Retrieve an Array of this collection’s unique Property names.
39 40 41 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 39 def names @names ||= Set[*map(&:name)].to_a.sort end |
#plain_text_properties ⇒ MicroMicro::Collections::PropertiesCollection
A collection of plain text Propertys parsed from the node.
48 49 50 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 48 def plain_text_properties @plain_text_properties ||= self.class.new(select(&:plain_text_property?)) end |
#plain_text_properties? ⇒ Boolean
Does this MicroMicro::Collections::PropertiesCollection include any plain text Propertys?
56 57 58 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 56 def plain_text_properties? plain_text_properties.any? end |
#to_h ⇒ Hash{Symbol => Array<String, Hash>}
Return a Hash of this collection’s Propertys as Arrays.
66 67 68 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 66 def to_h group_by(&:name).transform_keys(&:to_sym).deep_transform_values(&:value) end |
#url_properties ⇒ MicroMicro::Collections::PropertiesCollection
A collection of url Propertys parsed from the node.
75 76 77 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 75 def url_properties @url_properties ||= self.class.new(select(&:url_property?)) end |
#url_properties? ⇒ Boolean
Does this MicroMicro::Collections::PropertiesCollection include any url Propertys?
83 84 85 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 83 def url_properties? url_properties.any? end |
#values ⇒ Array<String, Hash>
Return an Array of this collection’s unique Property values.
93 94 95 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 93 def values @values ||= Set[*map(&:value)].to_a end |
#where(**args) {|property| ... } ⇒ MicroMicro::Collections::PropertiesCollection
Search this collection for Propertys matching the given conditions.
If a Hash is supplied, the returned collection will include Propertys matching all conditions. Keys must be Symbols matching an instance method on Property and values may be either a String or an Array of Strings.
When passing a block, each Property in this collection is yielded to the block and the returned collection will include Propertys that cause the block to return a value other than false
or nil
.
124 125 126 127 128 |
# File 'lib/micro_micro/collections/properties_collection.rb', line 124 def where(**args, &block) return self if args.none? && !block self.class.new(PropertiesCollectionSearch.new.search(self, **args, &block)) end |