Class: Paru::PandocFilter::Value

Inherits:
Node
  • Object
show all
Defined in:
lib/paru/filter/value.rb

Overview

A Value node that represents some sort of metadata about block or inline nodes

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Value

Create a new Value with contents. Also indicate if this node has inline children or block children.

Parameters:

  • contents (Array<pandoc node in JSON> = [])

    the contents of this node



37
38
39
40
41
42
43
44
45
# File 'lib/paru/filter/value.rb', line 37

def initialize(contents)
    @type = contents['t']

    if contents.has_key? 'c' then
      @value = contents['c']
    else
      @value = VALUE_ENCODED_IN_TYPE_NAME
    end
end

Instance Method Details

#ast_typeString

The AST type of this Node

Returns:

  • (String)


86
87
88
# File 'lib/paru/filter/value.rb', line 86

def ast_type()
    @type
end

#is_block?Boolean

Is this node a block?

Returns:

  • (Boolean)

    false



72
73
74
# File 'lib/paru/filter/value.rb', line 72

def is_block?
    false
end

#is_inline?Boolean

Is this node an inline node?

Returns:

  • (Boolean)

    false



79
80
81
# File 'lib/paru/filter/value.rb', line 79

def is_inline?
    false
end

#to_astHash

Create an AST representation of this Node

Returns:

  • (Hash)


93
94
95
96
97
98
# File 'lib/paru/filter/value.rb', line 93

def to_ast()
    return {
        "t" => ast_type,
        "c" => if type_encodes_value? then nil else @value end
    }
end

#type_encodes_value?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/paru/filter/value.rb', line 101

def type_encodes_value?()
    return @value == VALUE_ENCODED_IN_TYPE_NAME
end

#valueAny

Get the encoded value

Returns:

  • (Any)


50
51
52
53
54
55
56
# File 'lib/paru/filter/value.rb', line 50

def value()
    if type_encodes_value? then
        @type
    else
        @value
    end
end

#value=(new_value) ⇒ Object

Set the encoded value

Parameters:

  • new_value (Any)


61
62
63
64
65
66
67
# File 'lib/paru/filter/value.rb', line 61

def value=(new_value)
    if type_encodes_value? then
      @type = new_value
    else
      @value = new_value
    end
end