Class: Referral::Value::Token
- Inherits:
-
Struct
- Object
- Struct
- Referral::Value::Token
- Defined in:
- lib/referral/value/token.rb
Instance Attribute Summary collapse
-
#arity ⇒ Object
Returns the value of attribute arity.
-
#column ⇒ Object
Returns the value of attribute column.
-
#file ⇒ Object
Returns the value of attribute file.
-
#identifiers ⇒ Object
Returns the value of attribute identifiers.
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
-
#node_type ⇒ Object
Returns the value of attribute node_type.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #full_name ⇒ Object
- #full_name_tokens ⇒ Object
- #id ⇒ Object
- #literal_name ⇒ Object
- #literal_name_tokens ⇒ Object
- #scope ⇒ Object
- #scope_and_names ⇒ Object
- #scope_tokens ⇒ Object
- #type_name ⇒ Object
Instance Attribute Details
#arity ⇒ Object
Returns the value of attribute arity
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def arity @arity end |
#column ⇒ Object
Returns the value of attribute column
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def column @column end |
#file ⇒ Object
Returns the value of attribute file
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def file @file end |
#identifiers ⇒ Object
Returns the value of attribute identifiers
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def identifiers @identifiers end |
#line ⇒ Object
Returns the value of attribute line
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def line @line end |
#name ⇒ Object
Returns the value of attribute name
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def name @name end |
#node_type ⇒ Object
Returns the value of attribute node_type
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def node_type @node_type end |
#parent ⇒ Object
Returns the value of attribute parent
5 6 7 |
# File 'lib/referral/value/token.rb', line 5 def parent @parent end |
Instance Method Details
#ancestors ⇒ Object
27 28 29 30 |
# File 'lib/referral/value/token.rb', line 27 def ancestors return [] if parent.nil? [*parent.ancestors, parent] end |
#full_name ⇒ Object
32 33 34 |
# File 'lib/referral/value/token.rb', line 32 def full_name join_names(full_name_tokens) end |
#full_name_tokens ⇒ Object
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 |
#id ⇒ Object
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_name ⇒ Object
43 44 45 |
# File 'lib/referral/value/token.rb', line 43 def literal_name join_names(literal_name_tokens) end |
#literal_name_tokens ⇒ Object
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 |
#scope ⇒ Object
17 18 19 |
# File 'lib/referral/value/token.rb', line 17 def scope join_names(scope_tokens) end |
#scope_and_names ⇒ Object
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_tokens ⇒ Object
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_name ⇒ Object
55 56 57 |
# File 'lib/referral/value/token.rb', line 55 def type_name node_type.name.to_s end |