require_relative "./object" require_relative "../alma_api" class AlmaApi::Collection < Delegator def initialize(hash, items_key, item_class = AlmaApi::Object) hash.each do |_key, _value| if _key != items_key singleton_class.class_eval do attr_accessor "#{_key}".to_sym end instance_variable_set("@#{_key}".to_sym, _value) end end @items = hash.try(:[], items_key).try(:map) do |_item| item_class.new(_item) end || [] end def __getobj__ @items end def __setobj__(obj) @items = obj end end