class Nanoc::Core::BasicItemRepCollectionView

Public Class Methods

new(item_reps, context) click to toggle source

@api private

Calls superclass method Nanoc::Core::View::new
# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 15
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::Core::BasicItemRepView] if an item rep with the given name was found

# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 58
def [](rep_name)
  case rep_name
  when Symbol
    res = @item_reps.find { |ir| ir.name == rep_name }
    res && view_class.new(res, @context)
  when Integer
    raise ArgumentError, "expected BasicItemRepCollectionView#[] to be called with a symbol (you likely want `.reps[:default]` rather than `.reps[#{rep_name}]`)"
  else
    raise ArgumentError, 'expected BasicItemRepCollectionView#[] to be called with a symbol'
  end
end
_unwrap() click to toggle source

@api private

# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 21
def _unwrap
  @item_reps
end
each() { |view_class| ... } click to toggle source

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

@yieldparam [Object] item rep view

@yieldreturn [void]

@return [self]

# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 41
def each
  @item_reps.each { |ir| yield view_class.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::Core::BasicItemRepView]

@raise if no rep was found

# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 78
def fetch(rep_name)
  res = @item_reps.find { |ir| ir.name == rep_name }
  if res
    view_class.new(res, @context)
  else
    raise NoSuchItemRepError.new(rep_name)
  end
end
size() click to toggle source

@return [Integer]

# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 47
def size
  @item_reps.size
end
to_ary() click to toggle source
# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 30
def to_ary
  @item_reps.map { |ir| view_class.new(ir, @context) }
end
view_class() click to toggle source

@api private

# File lib/nanoc/core/basic_item_rep_collection_view.rb, line 26
def view_class
  Nanoc::Core::BasicItemRepView
end