class Referral::Value::Token
Public Instance Methods
ancestors()
click to toggle source
# File lib/referral/value/token.rb, line 27 def ancestors return [] if parent.nil? [*parent.ancestors, parent] end
full_name()
click to toggle source
# File lib/referral/value/token.rb, line 32 def full_name join_names(full_name_tokens) end
full_name_tokens()
click to toggle source
# 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
id()
click to toggle source
# 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_name()
click to toggle source
# File lib/referral/value/token.rb, line 43 def literal_name join_names(literal_name_tokens) end
literal_name_tokens()
click to toggle source
# File lib/referral/value/token.rb, line 47 def literal_name_tokens if identifiers && !identifiers.empty? identifiers else [self] end end
scope()
click to toggle source
# File lib/referral/value/token.rb, line 17 def scope join_names(scope_tokens) end
scope_and_names()
click to toggle source
# File lib/referral/value/token.rb, line 10 def scope_and_names [ *parent&.scope_and_names, *literal_name_tokens, ].compact end
scope_tokens()
click to toggle source
# 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_name()
click to toggle source
# File lib/referral/value/token.rb, line 55 def type_name node_type.name.to_s end
Protected Instance Methods
include_parents_in_full_name?()
click to toggle source
# File lib/referral/value/token.rb, line 69 def include_parents_in_full_name? node_type.token_type == :definition && node_type.good_parent == true end
join_names(tokens)
click to toggle source
# File lib/referral/value/token.rb, line 73 def join_names(tokens) tokens.reduce("") { |s, token| next s unless token.name if s.empty? token.name.to_s else "#{s}#{token.node_type.join_separator}#{token.name}" end } end