Class: Vitreous::Share::Element
- Inherits:
-
Mustache
- Object
- Mustache
- Vitreous::Share::Element
- Defined in:
- lib/vitreous/share/element.rb
Instance Method Summary collapse
- #collection? ⇒ Boolean
- #collections ⇒ Object
- #elements ⇒ Object
-
#initialize(hash) ⇒ Element
constructor
A new instance of Element.
- #item? ⇒ Boolean
- #items ⇒ Object
- #meta_methods ⇒ Object
- #to_md(text) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Element
Returns a new instance of Element.
4 5 6 7 |
# File 'lib/vitreous/share/element.rb', line 4 def initialize( hash ) @hash = hash end |
Instance Method Details
#collection? ⇒ Boolean
17 18 19 |
# File 'lib/vitreous/share/element.rb', line 17 def collection? @hash['type'] == 'collection' end |
#collections ⇒ Object
29 30 31 |
# File 'lib/vitreous/share/element.rb', line 29 def collections @hash['elements'].select { |e| e['type'] == 'collection' }.map { |e| Element.new( e ) } end |
#elements ⇒ Object
25 26 27 |
# File 'lib/vitreous/share/element.rb', line 25 def elements @hash['elements'].map { |e| Element.new( e ) } end |
#item? ⇒ Boolean
21 22 23 |
# File 'lib/vitreous/share/element.rb', line 21 def item? @hash['type'] == 'item' end |
#items ⇒ Object
33 34 35 |
# File 'lib/vitreous/share/element.rb', line 33 def items @hash['elements'].select { |e| e['type'] == 'item' }.map { |e| Element.new( e ) } end |
#meta_methods ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/vitreous/share/element.rb', line 9 def @hash.each do |k,v| (class << self; self; end).class_eval do define_method( k.to_sym ) { v } if !method_defined?( k.to_sym ) end end end |
#to_md(text) ⇒ Object
37 38 39 |
# File 'lib/vitreous/share/element.rb', line 37 def to_md( text ) RDiscount.new( render( text ) ).to_html end |