Class: Vitreous::Share::Element

Inherits:
Mustache
  • Object
show all
Defined in:
lib/vitreous/share/element.rb

Instance Method Summary collapse

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
  meta_methods
end

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vitreous/share/element.rb', line 17

def collection?
  @hash['type'] == 'collection'
end

#collectionsObject



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

#elementsObject



25
26
27
# File 'lib/vitreous/share/element.rb', line 25

def elements
  @hash['elements'].map { |e| Element.new( e ) }
end

#item?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/vitreous/share/element.rb', line 21

def item?
  @hash['type'] == 'item'
end

#itemsObject



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_methodsObject



9
10
11
12
13
14
15
# File 'lib/vitreous/share/element.rb', line 9

def meta_methods
  @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