Class: Paru::PandocFilter::MetaMap
- Includes:
- Enumerable
- Defined in:
- lib/paru/filter/meta_map.rb
Overview
A MetaMap Node is a map of String keys with MetaValue values
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#[](key) ⇒ MetaValue
Get the value belonging to key.
-
#[]=(key, value) ⇒ Object
Set a value with a key.
-
#ast_contents ⇒ Object
The AST contents.
-
#each(&block) ⇒ Object
Execute block for each key-value pair.
-
#initialize(contents = {}) ⇒ MetaMap
constructor
Create a new MetaMap based on the contents.
Methods inherited from Node
#ast_type, #can_act_as_both_block_and_inline?, from_markdown, #get_replacement, #has_been_replaced?, #has_block?, #has_children?, #has_class?, #has_inline?, #has_parent?, #has_string?, #is_block?, #is_inline?, #is_leaf?, #is_node?, #is_root?, #markdown, #markdown=, #toMetadata, #to_ast, #to_s, #type
Methods included from ASTManipulation
#append, #delete, #each_depth_first, #find_index, #get, #insert, #prepend, #remove_at, #replace, #replace_at
Constructor Details
#initialize(contents = {}) ⇒ MetaMap
Create a new MetaMap based on the contents
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/paru/filter/meta_map.rb', line 35 def initialize(contents = {}) @children = {} return unless contents.is_a? Hash contents.each_pair do |key, value| if !value.empty? && PandocFilter.const_defined?(value['t']) @children[key] = PandocFilter.const_get(value['t']).new value['c'] end end end |
Instance Method Details
#[](key) ⇒ MetaValue
Get the value belonging to key.
52 53 54 |
# File 'lib/paru/filter/meta_map.rb', line 52 def [](key) @children[key] end |
#[]=(key, value) ⇒ Object
Set a value with a key.
60 61 62 |
# File 'lib/paru/filter/meta_map.rb', line 60 def []=(key, value) @children[key] = value end |
#ast_contents ⇒ Object
The AST contents
70 71 72 73 74 75 76 77 78 |
# File 'lib/paru/filter/meta_map.rb', line 70 def ast_contents ast = {} if @children.is_a? Hash @children.each_pair do |key, value| ast[key] = value.to_ast end end ast end |
#each(&block) ⇒ Object
Execute block for each key-value pair
65 66 67 |
# File 'lib/paru/filter/meta_map.rb', line 65 def each(&block) @children.each(&block) end |