Class: Microformats2::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, url = nil) ⇒ Collection

Returns a new instance of Collection.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/microformats2/collection.rb', line 5

def initialize(element, url = nil)
  @element = element

  @base = nil
  if url != nil
    @base = url
  end
  if @element.search("base").size > 0
    @base = @element.search("base")[0].attribute("href")
  end

  @format_names = []
  @rels = {}
  @alternates = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/microformats2/collection.rb', line 3

def items
  @items
end

Instance Method Details

#allObject



35
36
37
38
# File 'lib/microformats2/collection.rb', line 35

def all
  warn "[DEPRECATION] `all` is deprecated and will be removed in the next release.  Please use `items` instead."
  items
end

#firstObject



40
41
42
43
# File 'lib/microformats2/collection.rb', line 40

def first
  warn "[DEPRECATION] `first` is deprecated and will be removed in the next release.  Please use `items.first` instead."
  items.first
end

#lastObject



45
46
47
48
# File 'lib/microformats2/collection.rb', line 45

def last
  warn "[DEPRECATION] `last` is deprecated and will be removed in the next release.  Please use `items.last` instead."
  items.last
end

#parseObject



21
22
23
24
25
# File 'lib/microformats2/collection.rb', line 21

def parse
  items
  parse_rels
  self
end

#to_hashObject



50
51
52
53
54
55
56
57
58
# File 'lib/microformats2/collection.rb', line 50

def to_hash
  hash = { items: [], rels: @rels }
  items.each do |format|
    hash[:items] << format.to_hash
  end
  hash[:alternates] = @alternates unless @alternates.nil? || @alternates.empty?

  hash
end

#to_jsonObject



60
61
62
# File 'lib/microformats2/collection.rb', line 60

def to_json
  to_hash.to_json
end