Class: Referral::Value::Token

Inherits:
Struct
  • Object
show all
Defined in:
lib/referral/value/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#arityObject

Returns the value of attribute arity

Returns:

  • (Object)

    the current value of arity



5
6
7
# File 'lib/referral/value/token.rb', line 5

def arity
  @arity
end

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



5
6
7
# File 'lib/referral/value/token.rb', line 5

def column
  @column
end

#fileObject

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



5
6
7
# File 'lib/referral/value/token.rb', line 5

def file
  @file
end

#identifiersObject

Returns the value of attribute identifiers

Returns:

  • (Object)

    the current value of identifiers



5
6
7
# File 'lib/referral/value/token.rb', line 5

def identifiers
  @identifiers
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



5
6
7
# File 'lib/referral/value/token.rb', line 5

def line
  @line
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/referral/value/token.rb', line 5

def name
  @name
end

#node_typeObject

Returns the value of attribute node_type

Returns:

  • (Object)

    the current value of node_type



5
6
7
# File 'lib/referral/value/token.rb', line 5

def node_type
  @node_type
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



5
6
7
# File 'lib/referral/value/token.rb', line 5

def parent
  @parent
end

Instance Method Details

#ancestorsObject



27
28
29
30
# File 'lib/referral/value/token.rb', line 27

def ancestors
  return [] if parent.nil?
  [*parent.ancestors, parent]
end

#full_nameObject



32
33
34
# File 'lib/referral/value/token.rb', line 32

def full_name
  join_names(full_name_tokens)
end

#full_name_tokensObject



36
37
38
39
40
41
# File 'lib/referral/value/token.rb', line 36

def full_name_tokens
  [
    *(include_parents_in_full_name? ? parent&.scope_and_names : []),
    *literal_name_tokens,
  ].compact
end

#idObject



59
60
61
62
63
64
65
# File 'lib/referral/value/token.rb', line 59

def id
  Digest::SHA1.hexdigest(to_h.merge(
    parent: nil,
    identifiers: identifiers&.map(&:id),
    node_type: node_type.name
  ).inspect)[0..6]
end

#literal_nameObject



43
44
45
# File 'lib/referral/value/token.rb', line 43

def literal_name
  join_names(literal_name_tokens)
end

#literal_name_tokensObject



47
48
49
50
51
52
53
# File 'lib/referral/value/token.rb', line 47

def literal_name_tokens
  if identifiers && !identifiers.empty?
    identifiers
  else
    [self]
  end
end

#scopeObject



17
18
19
# File 'lib/referral/value/token.rb', line 17

def scope
  join_names(scope_tokens)
end

#scope_and_namesObject



10
11
12
13
14
15
# File 'lib/referral/value/token.rb', line 10

def scope_and_names
  [
    *parent&.scope_and_names,
    *literal_name_tokens,
  ].compact
end

#scope_tokensObject



21
22
23
24
25
# File 'lib/referral/value/token.rb', line 21

def scope_tokens
  return [] if parent.nil?

  ancestors.take_while { |t| t.node_type.good_parent }.flat_map(&:literal_name_tokens)
end

#type_nameObject



55
56
57
# File 'lib/referral/value/token.rb', line 55

def type_name
  node_type.name.to_s
end