Class: Nanoc::IdentifiableCollectionView
- Includes:
- Enumerable
- Defined in:
- lib/nanoc/base/views/identifiable_collection_view.rb
Direct Known Subclasses
ItemCollectionWithRepsView, ItemCollectionWithoutRepsView, LayoutCollectionView, MutableIdentifiableCollectionView, PostCompileItemCollectionView
Instance Method Summary collapse
- #[](arg) ⇒ Object
-
#each {|object| ... } ⇒ self
Calls the given block once for each object, passing that object as a parameter.
-
#find_all(arg) ⇒ Enumerable
Finds all objects whose identifier matches the given argument.
-
#initialize(objects, context) ⇒ IdentifiableCollectionView
constructor
private
A new instance of IdentifiableCollectionView.
- #size ⇒ Integer
- #unwrap ⇒ Object private
- #view_class ⇒ Object abstract private
Methods inherited from View
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
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.
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.
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 |
#size ⇒ Integer
36 37 38 |
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 36 def size @objects.size end |
#unwrap ⇒ Object
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_class ⇒ Object
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.
19 20 21 |
# File 'lib/nanoc/base/views/identifiable_collection_view.rb', line 19 def view_class raise NotImplementedError end |