Class: Hyde::Set

Inherits:
Array
  • Object
show all
Defined in:
lib/hyde/set.rb

Instance Method Summary collapse

Instance Method Details

#except(by = {}) ⇒ Object

Method: except (Hyde::Set) Filters a set by removing items matching the given metadata criteria.

This is the opposite of find.

## Example

Page['/'].children.find(layout: 'default')


26
27
28
29
30
# File 'lib/hyde/set.rb', line 26

def except(by={})
  self.class.new(reject do |page|
    by.inject(true) { |b, (field, value)| b &&= (page.meta.send(field) == value) }
  end)
end

#find(by = {}) ⇒ Object

Method: find (Hyde::Set) Filters a set by given metadata criteria.

## Example

Page['/'].children.find(layout: 'default')


12
13
14
15
16
# File 'lib/hyde/set.rb', line 12

def find(by={})
  self.class.new(select do |page|
    by.inject(true) { |b, (field, value)| b &&= (page.meta.send(field) == value) }
  end)
end