Class: Eprayim::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/eprayim/element.rb,
lib/eprayim/render/html.rb

Constant Summary collapse

TYPES =
%w{ doc head para quote code list olist hr bold strong deleted italic icode image link }.map(&:to_sym)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, *args) ⇒ Element

Returns a new instance of Element.



10
11
12
13
14
# File 'lib/eprayim/element.rb', line 10

def initialize(type, *args)
  @type = type.to_sym
  @children = args || []
  raise "Bad element type: #{@type}" if not TYPES.include? @type
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



8
9
10
# File 'lib/eprayim/element.rb', line 8

def children
  @children
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/eprayim/element.rb', line 7

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
19
20
# File 'lib/eprayim/element.rb', line 16

def ==(other)
  return self.type == other.type && self.children == other.children
rescue
  return false
end

#inspectObject



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

def inspect
  "#{self.type}: #{self.children}"
end

#to_htmlObject



30
31
32
# File 'lib/eprayim/render/html.rb', line 30

def to_html
  @html ||= Render::HTML.render(self)
end