class Nanoc::IdentifiableCollectionView
Public Class Methods
new(objects, context)
click to toggle source
@api private
Calls superclass method
Nanoc::View.new
# File lib/nanoc/base/views/identifiable_collection_view.rb, line 6 def initialize(objects, context) super(context) @objects = objects end
Public Instance Methods
[](arg)
click to toggle source
@overload [](string)
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. @param [String] string @return [nil] if no object matches the string @return [#identifier] if an object was found
@overload [](regex)
Finds the object whose identifier matches the given regular expression. @param [Regex] regex @return [nil] if no object matches the regex @return [#identifier] if an object was found
# File lib/nanoc/base/views/identifiable_collection_view.rb, line 72 def [](arg) res = @objects[arg] res && view_class.new(res, @context) end
each() { |view_class| ... }
click to toggle source
Calls the given block once for each object, passing that object as a parameter.
@yieldparam [#identifier] object
@yieldreturn [void]
@return [self]
# 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)
click to toggle source
Finds all objects whose identifier matches the given argument.
@param [String, Regex] arg
@return [Enumerable]
# 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()
click to toggle source
@return [Integer]
# File lib/nanoc/base/views/identifiable_collection_view.rb, line 36 def size @objects.size end
unwrap()
click to toggle source
@api private
# File lib/nanoc/base/views/identifiable_collection_view.rb, line 12 def unwrap @objects end
view_class()
click to toggle source
@abstract
@api private
# File lib/nanoc/base/views/identifiable_collection_view.rb, line 19 def view_class raise NotImplementedError end