Class: Microformat::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/microformat/collection.rb

Instance Method Summary collapse

Instance Method Details

#<<(element) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/microformat/collection.rb', line 5

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

#filter(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/microformat/collection.rb', line 14

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