class HornOfPlenty::Collection

Attributes

items[RW]
parser[RW]
raw_items[RW]

Public Class Methods

new(items:, parser:) click to toggle source
# File lib/horn_of_plenty/collection.rb, line 15
def initialize(items:, parser:)
  self.raw_items = items
  self.parser    = parser
end

Public Instance Methods

[](index) click to toggle source
# File lib/horn_of_plenty/collection.rb, line 20
def [](index)
  items[index] ||= transform(raw_items[index])
end
each() { |items| ... } click to toggle source
# File lib/horn_of_plenty/collection.rb, line 38
def each
  raw_items.each_with_index do |raw_item, index|
    items[index] = items[index] || transform(raw_item)

    yield items[index]
  end
end
first() click to toggle source
# File lib/horn_of_plenty/collection.rb, line 24
def first
  items[0] ||= transform(raw_items[0])
end
pop(*args) click to toggle source
# File lib/horn_of_plenty/collection.rb, line 33
def pop(*args)
  raw_items.pop(*args)
  items.pop(*args)
end
shift(*args) click to toggle source
# File lib/horn_of_plenty/collection.rb, line 28
def shift(*args)
  raw_items.shift(*args)
  items.shift(*args)
end

Protected Instance Methods

transform(raw_item) click to toggle source
# File lib/horn_of_plenty/collection.rb, line 52
def transform(raw_item)
  parser.to_model(raw_item)
end