Class: Nanoc::IdentifiableCollectionView

Inherits:
View
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nanoc/base/views/identifiable_collection_view.rb

Instance Method Summary collapse

Methods inherited from View

#_context, #frozen?, #inspect

Constructor Details

#initialize(objects, context) ⇒ IdentifiableCollectionView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of IdentifiableCollectionView.



6
7
8
9
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 6

def initialize(objects, context)
  super(context)
  @objects = objects
end

Instance Method Details

#[](string) ⇒ nil, #identifier #[](regex) ⇒ nil, #identifier

Overloads:

  • #[](string) ⇒ nil, #identifier

    Finds the object whose identifier matches the given string.

    If the glob syntax is enabled, the string can be a glob, in which case this method finds the first object that matches the given glob.

    Parameters:

    Returns:

    • (nil)

      if no object matches the string

    • (#identifier)

      if an object was found

  • #[](regex) ⇒ nil, #identifier

    Finds the object whose identifier matches the given regular expression.

    Parameters:

    • regex (Regex)

    Returns:

    • (nil)

      if no object matches the regex

    • (#identifier)

      if an object was found



72
73
74
75
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 72

def [](arg)
  res = @objects[arg]
  res && view_class.new(res, @context)
end

#each {|object| ... } ⇒ self

Calls the given block once for each object, passing that object as a parameter.

Yield Parameters:

  • object (#identifier)

Yield Returns:

  • (void)

Returns:

  • (self)


30
31
32
33
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 30

def each
  @objects.each { |i| yield view_class.new(i, @context) }
  self
end

#find_all(arg) ⇒ Enumerable

Finds all objects whose identifier matches the given argument.

Parameters:

Returns:

  • (Enumerable)


45
46
47
48
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 45

def find_all(arg)
  pat = Nanoc::Int::Pattern.from(arg)
  select { |i| pat.match?(i.identifier) }
end

#sizeInteger

Returns:

  • (Integer)


36
37
38
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 36

def size
  @objects.size
end

#unwrapObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 12

def unwrap
  @objects
end

#view_classObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 19

def view_class
  raise NotImplementedError
end