Class: Ast::Crispr::OwnerSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/crispr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, locate:, owned_span: nil, anchor: nil, limit: nil, metadata: {}, **options) ⇒ OwnerSelector

Returns a new instance of OwnerSelector.



777
778
779
780
781
782
783
784
# File 'lib/ast/crispr.rb', line 777

def initialize(id:, locate:, owned_span: nil, anchor: nil, limit: nil, metadata: {}, **options)
  @id = id
  @locate = locate
  @owned_span = owned_span
  @anchor = anchor
  @limit = Limit.coerce(limit, default: { exactly: 1 })
  @metadata = .merge(options)
end

Instance Attribute Details

#anchorObject (readonly)

Returns the value of attribute anchor.



775
776
777
# File 'lib/ast/crispr.rb', line 775

def anchor
  @anchor
end

#idObject (readonly)

Returns the value of attribute id.



775
776
777
# File 'lib/ast/crispr.rb', line 775

def id
  @id
end

#limitObject (readonly)

Returns the value of attribute limit.



775
776
777
# File 'lib/ast/crispr.rb', line 775

def limit
  @limit
end

#locateObject (readonly)

Returns the value of attribute locate.



775
776
777
# File 'lib/ast/crispr.rb', line 775

def locate
  @locate
end

#metadataObject (readonly)

Returns the value of attribute metadata.



775
776
777
# File 'lib/ast/crispr.rb', line 775

def 
  @metadata
end

#owned_spanObject (readonly)

Returns the value of attribute owned_span.



775
776
777
# File 'lib/ast/crispr.rb', line 775

def owned_span
  @owned_span
end

Instance Method Details

#comment_regionObject



817
818
819
# File 'lib/ast/crispr.rb', line 817

def comment_region
  [:comment_region]&.to_sym
end

#include_trailing_gap?Boolean

Returns:

  • (Boolean)


821
822
823
# File 'lib/ast/crispr.rb', line 821

def include_trailing_gap?
  [:include_trailing_gap] ? true : false
end

#locate_matches(context) ⇒ Object



786
787
788
# File 'lib/ast/crispr.rb', line 786

def locate_matches(context)
  Array(invoke(locate, context)).flatten.compact.map { |candidate| coerce_match(candidate) }
end

#owner_scopeObject



801
802
803
# File 'lib/ast/crispr.rb', line 801

def owner_scope
  .fetch(:owner_scope, :shared_default)
end

#resolve_anchor(context, match = nil) ⇒ Object



795
796
797
798
799
# File 'lib/ast/crispr.rb', line 795

def resolve_anchor(context, match = nil)
  return unless anchor

  invoke(anchor, context, match)
end

#resolve_owned_match(context, match) ⇒ Object



790
791
792
793
# File 'lib/ast/crispr.rb', line 790

def resolve_owned_match(context, match)
  candidate = owned_span ? invoke(owned_span, context, match) : match
  coerce_match(candidate).with_target(self)
end

#selection_intentObject



813
814
815
# File 'lib/ast/crispr.rb', line 813

def selection_intent
  [:selection_intent]&.to_sym
end

#selection_profile(context) ⇒ Object



825
826
827
828
829
830
831
832
833
834
835
# File 'lib/ast/crispr.rb', line 825

def selection_profile(context)
  SelectionProfile.new(
    owner_scope: owner_scope,
    selector_kind: selector_kind,
    selection_intent: selection_intent,
    comment_region: comment_region,
    include_trailing_gap: include_trailing_gap?,
    structure_profile: structure_profile(context),
    metadata: 
  )
end

#selector_kindObject



809
810
811
# File 'lib/ast/crispr.rb', line 809

def selector_kind
  [:selector_kind]&.to_sym
end

#structure_profile(context) ⇒ Object



805
806
807
# File 'lib/ast/crispr.rb', line 805

def structure_profile(context)
  context.structure_profile(owner_scope: owner_scope)
end