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)


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

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

#collectionsObject



38
39
40
# File 'lib/vitreous/share/element.rb', line 38

def collections
  @hash['elements'].select { |e| e['type'] == 'collection' }.map { |e| Element.new( e ) }
end

#elementsObject



34
35
36
# File 'lib/vitreous/share/element.rb', line 34

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

#home?Boolean

Returns:

  • (Boolean)


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

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

#item?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/vitreous/share/element.rb', line 30

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

#itemsObject



42
43
44
# File 'lib/vitreous/share/element.rb', line 42

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

#not_found?Boolean

Returns:

  • (Boolean)


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

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

#to_md(text) ⇒ Object



46
47
48
# File 'lib/vitreous/share/element.rb', line 46

def to_md( text )
  RDiscount.new( render( text ) ).to_html
end