Sha256: 00f146b2de3ccc3989e781b2d7927c8898433bd7ac1c204577e59c97c5cd76bf

Contents?: true

Size: 777 Bytes

Versions: 6

Compression:

Stored size: 777 Bytes

Contents

# Class: Proton::Set
# A set of pages.

class Proton
class Set < Array
  # Method: find (Proton::Set)
  # Filters a set by given metadata criteria.
  #
  # ##  Example
  #     Page['/'].children.find(layout: 'default')
  #
  def find(by={})
    self.class.new(select do |page|
      by.inject(true) { |b, (field, value)| b &&= (page.meta.send(field) == value) }
    end)
  end

  # Method: except (Proton::Set)
  # Filters a set by removing items matching the given metadata criteria.
  #
  # This is the opposite of {Proton::Set::find}.
  #
  # ##  Example
  #     Page['/'].children.find(layout: 'default')
  #
  def except(by={})
    self.class.new(reject do |page|
      by.inject(true) { |b, (field, value)| b &&= (page.meta.send(field) == value) }
    end)
  end
end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
proton-0.3.6 lib/proton/set.rb
proton-0.3.5 lib/proton/set.rb
proton-0.3.4 lib/proton/set.rb
proton-0.3.3 lib/proton/set.rb
proton-0.3.2 lib/proton/set.rb
proton-0.3.0.rc1 lib/proton/set.rb