Class: StructuredData::BreadcrumbList
- Inherits:
-
Object
- Object
- StructuredData::BreadcrumbList
- Defined in:
- lib/structured_data.rb
Defined Under Namespace
Classes: Item
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #add(item) ⇒ Object
- #dump ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ BreadcrumbList
constructor
A new instance of BreadcrumbList.
- #size ⇒ Object
Constructor Details
#initialize ⇒ BreadcrumbList
Returns a new instance of BreadcrumbList.
21 22 23 |
# File 'lib/structured_data.rb', line 21 def initialize @items = [] end |
Instance Method Details
#<<(item) ⇒ Object
29 30 31 |
# File 'lib/structured_data.rb', line 29 def <<(item) add(item) end |
#add(item) ⇒ Object
25 26 27 |
# File 'lib/structured_data.rb', line 25 def add(item) @items << item end |
#dump ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/structured_data.rb', line 37 def dump hash = { "@context": "http://schema.org", "@type": "BreadcrumbList", } hash['itemListElement'] = items_to_hash JSON.pretty_generate(hash) end |
#each(&block) ⇒ Object
47 48 49 |
# File 'lib/structured_data.rb', line 47 def each(&block) @items.map { |i| Item.new(i[:url], i[:name]) }.each(&block) end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/structured_data.rb', line 33 def empty? @items.empty? end |
#size ⇒ Object
51 52 53 |
# File 'lib/structured_data.rb', line 51 def size @items.size end |