Sha256: 002c2d9c7ddae43e82f09339a27516ee786c95fb92317c5b05e8d53b532f6291
Contents?: true
Size: 684 Bytes
Versions: 7
Compression:
Stored size: 684 Bytes
Contents
require "microformat/selectors" module Microformat class Collection < ::Array def <<(element) # load the first matching format format = Selectors.class_matching(element) # use the microformat to parse the element parsed = format.parse(element) # add the parsed object to the array super(parsed) end def filter(*args) classes = Array(args).flatten # find the applicable classes filtered = select do |object| Array(classes).include?(object.class) end # create a new collection from them self.class.new.tap do |collection| collection.replace(filtered) end end end end
Version data entries
7 entries across 7 versions & 2 rubygems