Class: MetaCommit::Extension::MarkdownSupport::Models::Ast

Inherits:
Contracts::Ast
  • Object
show all
Defined in:
lib/meta_commit_markdown_support/models/ast.rb

Overview

Adapter which implements MetaCommit::Contracts::Ast contract and wraps CommonMarker::Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ Ast

Returns a new instance of Ast.

Parameters:

  • element (CommonMarker::Node)


8
9
10
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 8

def initialize(element)
  @element = element
end

Instance Attribute Details

#elementCommonMarker::Node

Returns the current value of element.

Returns:

  • (CommonMarker::Node)

    the current value of element



4
5
6
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 4

def element
  @element
end

Instance Method Details

#==(right_ast) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


43
44
45
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 43

def ==(right_ast)
  element == right_ast.element
end

#childrenArray<MetaCommit::Contracts::Ast>

Returns children ast.

Returns:

  • (Array<MetaCommit::Contracts::Ast>)

    children ast



13
14
15
16
17
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 13

def children
  element.each.map do |child|
    Ast.new(child)
  end
end

#first_columnInteger?

Returns column number where ast starts.

Returns:

  • (Integer, nil)

    column number where ast starts



30
31
32
33
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 30

def first_column
  return nil if element.sourcepos[:start_column].nil?
  element.sourcepos[:start_column] - 1
end

#first_lineInteger?

Returns line number where ast starts.

Returns:

  • (Integer, nil)

    line number where ast starts



20
21
22
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 20

def first_line
  element.sourcepos[:start_line]
end

#last_columnInteger?

Returns column number where ast ends.

Returns:

  • (Integer, nil)

    column number where ast ends



36
37
38
39
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 36

def last_column
  return nil if element.sourcepos[:end_column].nil?
  element.sourcepos[:end_column] - 1
end

#last_lineInteger?

Returns line number where ast ends.

Returns:

  • (Integer, nil)

    line number where ast ends



25
26
27
# File 'lib/meta_commit_markdown_support/models/ast.rb', line 25

def last_line
  element.sourcepos[:end_line]
end