Class: Microformats2::Collection
- Inherits:
-
Object
- Object
- Microformats2::Collection
- Defined in:
- lib/microformats2/collection.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #all ⇒ Object
- #first ⇒ Object
-
#initialize(element, url = nil) ⇒ Collection
constructor
A new instance of Collection.
- #last ⇒ Object
- #parse ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
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
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/microformats2/collection.rb', line 3 def items @items end |
Instance Method Details
#all ⇒ Object
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 |
#first ⇒ Object
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 |
#last ⇒ Object
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 |
#parse ⇒ Object
21 22 23 24 25 |
# File 'lib/microformats2/collection.rb', line 21 def parse items parse_rels self end |
#to_hash ⇒ Object
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_json ⇒ Object
60 61 62 |
# File 'lib/microformats2/collection.rb', line 60 def to_json to_hash.to_json end |