class Nanoc::ItemRepCollectionView
Public Class Methods
new(item_reps, context)
click to toggle source
@api private
Calls superclass method
Nanoc::View.new
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 12 def initialize(item_reps, context) super(context) @item_reps = item_reps end
Public Instance Methods
[](rep_name)
click to toggle source
Return the item rep with the given name, or nil if no item rep exists.
@param [Symbol] rep_name
@return [nil] if no item rep with the given name was found
@return [Nanoc::ItemRepView] if an item rep with the given name was found
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 50 def [](rep_name) case rep_name when Symbol res = @item_reps.find { |ir| ir.name == rep_name } res && Nanoc::ItemRepView.new(res, @context) when Fixnum raise ArgumentError, "expected ItemRepCollectionView#[] to be called with a symbol (you likely want `.reps[:default]` rather than `.reps[#{rep_name}]`)" else raise ArgumentError, 'expected ItemRepCollectionView#[] to be called with a symbol' end end
each() { |item_rep_view| ... }
click to toggle source
Calls the given block once for each item rep, passing that item rep as a parameter.
@yieldparam [Nanoc::ItemRepView] item rep
@yieldreturn [void]
@return [self]
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 33 def each @item_reps.each { |ir| yield Nanoc::ItemRepView.new(ir, @context) } self end
fetch(rep_name)
click to toggle source
Return the item rep with the given name, or raises an exception if there is no rep with the given name.
@param [Symbol] rep_name
@return [Nanoc::ItemRepView]
@raise if no rep was found
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 70 def fetch(rep_name) res = @item_reps.find { |ir| ir.name == rep_name } if res Nanoc::ItemRepView.new(res, @context) else raise NoSuchItemRepError.new(rep_name) end end
size()
click to toggle source
@return [Integer]
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 39 def size @item_reps.size end
to_ary()
click to toggle source
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 22 def to_ary @item_reps.map { |ir| Nanoc::ItemRepView.new(ir, @context) } end
unwrap()
click to toggle source
@api private
# File lib/nanoc/base/views/item_rep_collection_view.rb, line 18 def unwrap @item_reps end