Class: Newstile::Element
- Inherits:
-
Object
- Object
- Newstile::Element
- Defined in:
- lib/newstile/document.rb
Overview
Represents all elements in the parse tree.
newstile only uses this one class for representing all available elements in a parse tree (paragraphs, headers, emphasis, …). The type of element can be set via the #type accessor.
Instance Attribute Summary collapse
-
#attr ⇒ Object
readonly
The attributes of the element.
-
#children ⇒ Object
The child elements of this element.
-
#options ⇒ Object
The options hash for the element.
-
#type ⇒ Object
A symbol representing the element type.
-
#value ⇒ Object
The value of the element.
Instance Method Summary collapse
-
#initialize(type, value = nil, attr = nil, options = {}) ⇒ Element
constructor
Create a new Element object of type
type
. -
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(type, value = nil, attr = nil, options = {}) ⇒ Element
Create a new Element object of type type
. The optional parameters value
, attr
and options
can also be set in this constructor for convenience.
156 157 158 159 |
# File 'lib/newstile/document.rb', line 156 def initialize(type, value = nil, attr = nil, = {}) @type, @value, @attr, @options = type, value, Utils::OrderedHash.new(attr), @children = [] end |
Instance Attribute Details
#attr ⇒ Object (readonly)
The attributes of the element. Uses an Utils::OrderedHash to retain the insertion order.
140 141 142 |
# File 'lib/newstile/document.rb', line 140 def attr @attr end |
#children ⇒ Object
The child elements of this element.
151 152 153 |
# File 'lib/newstile/document.rb', line 151 def children @children end |
#options ⇒ Object
The options hash for the element. It is used for storing arbitray options as well as the following special contents:
-
Category of the element, either
:block
or:span
, under the:category
key. If this key is absent, it can be assumed that the element is in the:span
category.
148 149 150 |
# File 'lib/newstile/document.rb', line 148 def @options end |
#type ⇒ Object
A symbol representing the element type. For example, :p
or :blockquote
.
133 134 135 |
# File 'lib/newstile/document.rb', line 133 def type @type end |
#value ⇒ Object
The value of the element. The interpretation of this field depends on the type of the element. Many elements don’t use this field.
137 138 139 |
# File 'lib/newstile/document.rb', line 137 def value @value end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
161 162 163 |
# File 'lib/newstile/document.rb', line 161 def inspect #:nodoc: "<kd:#{@type}#{@value.nil? ? '' : ' ' + @value.inspect} #{@attr.inspect}#{.empty? ? '' : ' ' + @options.inspect}#{@children.empty? ? '' : ' ' + @children.inspect}>" end |