Class: Nanoc::ItemRepCollectionView
- Includes:
- Enumerable
- Defined in:
- lib/nanoc/base/views/item_rep_collection_view.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NoSuchItemRepError
Instance Method Summary collapse
-
#[](rep_name) ⇒ nil, Nanoc::ItemRepView
Return the item rep with the given name, or nil if no item rep exists.
-
#each {|item| ... } ⇒ self
Calls the given block once for each item rep, passing that item rep as a parameter.
-
#fetch(rep_name) ⇒ Nanoc::ItemRepView
Return the item rep with the given name, or raises an exception if there is no rep with the given name.
-
#size ⇒ Integer
-
#to_ary ⇒ Object
Methods inherited from View
Instance Method Details
#[](rep_name) ⇒ nil, Nanoc::ItemRepView
Return the item rep with the given name, or nil if no item rep exists.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nanoc/base/views/item_rep_collection_view.rb', line 55 def [](rep_name) case rep_name when Symbol res = @item_reps.find { |ir| ir.name == rep_name } res && view_class.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| ... } ⇒ self
Calls the given block once for each item rep, passing that item rep as a parameter.
38 39 40 41 |
# File 'lib/nanoc/base/views/item_rep_collection_view.rb', line 38 def each @item_reps.each { |ir| yield view_class.new(ir, @context) } self end |
#fetch(rep_name) ⇒ Nanoc::ItemRepView
Return the item rep with the given name, or raises an exception if there is no rep with the given name.
75 76 77 78 79 80 81 82 |
# File 'lib/nanoc/base/views/item_rep_collection_view.rb', line 75 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 ⇒ Integer
44 45 46 |
# File 'lib/nanoc/base/views/item_rep_collection_view.rb', line 44 def size @item_reps.size end |
#to_ary ⇒ Object
27 28 29 |
# File 'lib/nanoc/base/views/item_rep_collection_view.rb', line 27 def to_ary @item_reps.map { |ir| view_class.new(ir, @context) } end |