Parent

Included Modules

Class/Module Index [+]

Quicksearch

Nanoc::ItemArray

Acts as an array, but allows fetching items using identifiers, e.g. `@items`.

Public Class Methods

new() click to toggle source
# File lib/nanoc/base/source_data/item_array.rb, line 23
def initialize
  @items = []
end

Public Instance Methods

[](*args) click to toggle source
# File lib/nanoc/base/source_data/item_array.rb, line 33
def [](*args)
  if 1 == args.size && args.first.is_a?(String)
    self.item_with_identifier(args.first)
  else
    @items[*args]
  end
end
Also aliased as: slice
at(arg) click to toggle source
# File lib/nanoc/base/source_data/item_array.rb, line 42
def at(arg)
  if arg.is_a?(String)
    self.item_with_identifier(arg)
  else
    @items[arg]
  end
end
freeze() click to toggle source
# File lib/nanoc/base/source_data/item_array.rb, line 27
def freeze
  @items.freeze
  self.build_mapping
  super
end
slice(*args) click to toggle source
Alias for: []

Protected Instance Methods

build_mapping() click to toggle source
# File lib/nanoc/base/source_data/item_array.rb, line 60
def build_mapping
  @mapping = {}
  @items.each do |item|
    @mapping[item.identifier] = item
  end
  @mapping.freeze
end
item_with_identifier(identifier) click to toggle source
# File lib/nanoc/base/source_data/item_array.rb, line 52
def item_with_identifier(identifier)
  if self.frozen?
    @mapping[identifier]
  else
    @items.find { |i| i.identifier == identifier }
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.