Sha256: 551f222c33369b1adb70848d06daa881340de7f3239e81603d692a5549383fb3
Contents?: true
Size: 1.09 KB
Versions: 25
Compression:
Stored size: 1.09 KB
Contents
require 'active_support' class LHS::Collection < LHS::Proxy module InternalCollection extend ActiveSupport::Concern # The internal collection class that includes enumerable # and insures to return LHS::Items in case of iterating items class Collection include Enumerable attr_accessor :raw delegate :length, :size, :last, :sample, :[], :present?, :blank?, :empty?, :<<, :push, :compact, to: :raw def initialize(raw, parent, record) self.raw = raw @parent = parent @record = record end def to_ary map { |item| item } end def each(&_block) raw.each do |item| if item.is_a? Hash yield cast_item(item) else yield item end end end private def cast_item(item) record_by_href = LHS::Record.for_url(item[:href]) if item[:href] data = LHS::Data.new(item, @parent, @record) return (record_by_href || @record).new(data) if record_by_href || @record data end end end end
Version data entries
25 entries across 25 versions & 1 rubygems