Module: Utils

Included in:
Htmlize
Defined in:
lib/smart_diff/utils.rb

Class Method Summary collapse

Class Method Details

.get_install_pathPathname

Where in the file-system is smart_diff installed?

Returns:

  • (Pathname)

    the path to the installation of smart_diff



11
12
13
14
15
# File 'lib/smart_diff/utils.rb', line 11

def get_install_path
  utils_path = Pathname.new(__FILE__).dirname
  # There should be a more elegant way to do this
  install_path = utils_path.parent.parent
end

.inside_anchor?(tags, nd_start, nd_end) ⇒ TrueClass, FalseClass

Determines if the node beginning with nd_start and ending with nd_end falls inside an anchor. In other words, is the current node inside another node _which also changed_ and has a match in the other file. (If it is an insertion or deletion it gets wrapped in a span so we aren’t concerned with those.)

In a pair of tags, the opening tag only has some of the position information, so they are marked with a meaningless -1. But the closing tags have the information needed- start and end offsets.

Subnodes were added to the array after the outer nodes, so we check them here, once, against each tag, and decide how to process them as we generate the HTML.

Parameters:

  • tags (Array)

    A list of all tags so far recorded.

  • nd_start (Fixnum)

    Number representing the node’s starting position.

  • nd_end (Fixnum)

    Number representing the node’s ending position.

Returns:

  • (TrueClass, FalseClass)

    Is it inside an anchor?



60
61
62
63
64
65
66
67
# File 'lib/smart_diff/utils.rb', line 60

def inside_anchor?(tags, nd_start, nd_end)
    tags.each do |t|
      if nd_end < t.idx && nd_start > t.start && t.start != -1
        return true
      end
    end
    return false
end

.node_end(node) ⇒ Fixnum

Get a node’s end position.

Parameters:

  • node (org.jrubyparser.Node)

    a node in an abstract syntax tree

Returns:

  • (Fixnum)

    Number representing the node’s end offset.



35
36
37
# File 'lib/smart_diff/utils.rb', line 35

def node_end(node)
  node.position.end_offset
end

.node_start(node) ⇒ Fixnum

Get a node’s start position,

Parameters:

  • node (org.jrubyparser.Node)

    a node in an abstract syntax tree

Returns:

  • (Fixnum)

    Number representing the node’s start offset.



24
25
26
# File 'lib/smart_diff/utils.rb', line 24

def node_start(node)
  node.position.start_offset
end