Class: Paru::PandocFilter::DefinitionListItem

Inherits:
Block
  • Object
show all
Defined in:
lib/paru/filter/definition_list_item.rb

Overview

A DefinitionListItem is a helper node to represent the pair of a term and its definition in a DefinitionList

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ DefinitionListItem

Create a new DefinitionListItem

Parameters:

  • item (Array)

    the [term, definition]



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/paru/filter/definition_list_item.rb', line 39

def initialize(item)
    super []

    @term = Block.new item[0]
    @term.parent = self
    @children << @term

    @definition = List.new item[1]
    @definition.parent = self
    @children << @definition
end

Instance Attribute Details

#definitionList

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/paru/filter/definition_list_item.rb', line 33

class DefinitionListItem < Block
    attr_accessor :term, :definition

    # Create a new DefinitionListItem 
    #
    # @param item [Array] the [term, definition]
    def initialize(item)
        super []

        @term = Block.new item[0]
        @term.parent = self
        @children << @term

        @definition = List.new item[1]
        @definition.parent = self
        @children << @definition
    end

    # Create an AST representation of this DefinitionListItem
    def to_ast
        [
            @term.ast_contents,
            @definition.ast_contents
        ]
    end

    # Convert this DefinitionListItem to a pair of term and definition
    #
    # @return [Array]
    def to_array
        term = @term.children.map{|c| c.markdown.strip}.select{|c| !c.empty?}.join(" ").strip
        definition = @definition.children.map{|c| c.children.map{|d| d.markdown}}.join("\n").strip
        [term, definition]
    end
end

#termBlock

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/paru/filter/definition_list_item.rb', line 33

class DefinitionListItem < Block
    attr_accessor :term, :definition

    # Create a new DefinitionListItem 
    #
    # @param item [Array] the [term, definition]
    def initialize(item)
        super []

        @term = Block.new item[0]
        @term.parent = self
        @children << @term

        @definition = List.new item[1]
        @definition.parent = self
        @children << @definition
    end

    # Create an AST representation of this DefinitionListItem
    def to_ast
        [
            @term.ast_contents,
            @definition.ast_contents
        ]
    end

    # Convert this DefinitionListItem to a pair of term and definition
    #
    # @return [Array]
    def to_array
        term = @term.children.map{|c| c.markdown.strip}.select{|c| !c.empty?}.join(" ").strip
        definition = @definition.children.map{|c| c.children.map{|d| d.markdown}}.join("\n").strip
        [term, definition]
    end
end

Instance Method Details

#to_arrayArray

Convert this DefinitionListItem to a pair of term and definition

Returns:

  • (Array)


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

def to_array
    term = @term.children.map{|c| c.markdown.strip}.select{|c| !c.empty?}.join(" ").strip
    definition = @definition.children.map{|c| c.children.map{|d| d.markdown}}.join("\n").strip
    [term, definition]
end

#to_astObject

Create an AST representation of this DefinitionListItem



52
53
54
55
56
57
# File 'lib/paru/filter/definition_list_item.rb', line 52

def to_ast
    [
        @term.ast_contents,
        @definition.ast_contents
    ]
end