Class: Ast::Crispr::SelectionProfile
- Inherits:
-
Object
- Object
- Ast::Crispr::SelectionProfile
- Includes:
- ProfileReportCompatibility
- Defined in:
- lib/ast/crispr.rb,
lib/ast/crispr.rb
Constant Summary collapse
- KNOWN_SELECTION_INTENTS =
{ predicate_filter: { family: :predicate, description: 'Predicate-based structural owner filtering' }, comment_anchored_owner: { family: :comment_anchor, description: 'Comment-region marker anchored owner selection' }, section_branch: { family: :section_branch, description: 'Heading-owned section branch selection' } }.freeze
- KNOWN_SELECTOR_KINDS =
{ owner_filter: { family: :owner_filter }, comment_region_owner: { family: :comment_anchor }, comment_region_owned_owner: { family: :comment_anchor }, heading_section: { family: :section_branch } }.freeze
- KNOWN_COMMENT_REGIONS =
{ leading: { family: :leading }, trailing: { family: :trailing }, inline: { family: :inline } }.freeze
- COMPAT_SELECTION_INTENT_FAMILIES =
{ predicate_filter: :predicate, comment_anchored_owner: :comment_anchor, comment_region_filter: :comment, section_branch: :section_branch, section_heading: :section }.freeze
Instance Attribute Summary collapse
-
#comment_region ⇒ Object
readonly
Returns the value of attribute comment_region.
-
#include_trailing_gap ⇒ Object
readonly
Returns the value of attribute include_trailing_gap.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#owner_scope ⇒ Object
readonly
Returns the value of attribute owner_scope.
-
#selection_intent ⇒ Object
readonly
Returns the value of attribute selection_intent.
-
#selector_kind ⇒ Object
readonly
Returns the value of attribute selector_kind.
-
#structure_profile ⇒ Object
readonly
Returns the value of attribute structure_profile.
Instance Method Summary collapse
- #comment_anchored? ⇒ Boolean
-
#initialize(owner_scope:, selector_kind:, selection_intent:, structure_profile: nil, owner_selector: nil, comment_region: nil, include_trailing_gap: false, metadata: {}, **options) ⇒ SelectionProfile
constructor
A new instance of SelectionProfile.
- #known_selection_intent? ⇒ Boolean
- #owner_selector ⇒ Object
- #owner_selector_family ⇒ Object
- #report ⇒ Object
- #selection_intent_family ⇒ Object
- #selection_intent_metadata ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(owner_scope:, selector_kind:, selection_intent:, structure_profile: nil, owner_selector: nil, comment_region: nil, include_trailing_gap: false, metadata: {}, **options) ⇒ SelectionProfile
Returns a new instance of SelectionProfile.
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/ast/crispr.rb', line 511 def initialize(owner_scope:, selector_kind:, selection_intent:, structure_profile: nil, owner_selector: nil, comment_region: nil, include_trailing_gap: false, metadata: {}, **) @owner_scope = owner_scope&.to_sym @selector_kind = selector_kind&.to_sym @selection_intent = selection_intent&.to_sym @comment_region = comment_region&.to_sym @include_trailing_gap = include_trailing_gap ? true : false @structure_profile = structure_profile || StructureProfile.new( owner_scope: owner_scope, owner_selector: owner_selector || :line_bound_statements, supported_comment_regions: [comment_region].compact ) @metadata = .merge().freeze end |
Instance Attribute Details
#comment_region ⇒ Object (readonly)
Returns the value of attribute comment_region.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def comment_region @comment_region end |
#include_trailing_gap ⇒ Object (readonly)
Returns the value of attribute include_trailing_gap.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def include_trailing_gap @include_trailing_gap end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def @metadata end |
#owner_scope ⇒ Object (readonly)
Returns the value of attribute owner_scope.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def owner_scope @owner_scope end |
#selection_intent ⇒ Object (readonly)
Returns the value of attribute selection_intent.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def selection_intent @selection_intent end |
#selector_kind ⇒ Object (readonly)
Returns the value of attribute selector_kind.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def selector_kind @selector_kind end |
#structure_profile ⇒ Object (readonly)
Returns the value of attribute structure_profile.
508 509 510 |
# File 'lib/ast/crispr.rb', line 508 def structure_profile @structure_profile end |
Instance Method Details
#comment_anchored? ⇒ Boolean
547 548 549 |
# File 'lib/ast/crispr.rb', line 547 def comment_anchored? !comment_region.nil? end |
#known_selection_intent? ⇒ Boolean
543 544 545 |
# File 'lib/ast/crispr.rb', line 543 def known_selection_intent? KNOWN_SELECTION_INTENTS.key?(selection_intent) end |
#owner_selector ⇒ Object
531 532 533 |
# File 'lib/ast/crispr.rb', line 531 def owner_selector structure_profile.owner_selector end |
#owner_selector_family ⇒ Object
535 536 537 |
# File 'lib/ast/crispr.rb', line 535 def owner_selector_family structure_profile.owner_selector_family end |
#report ⇒ Object
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 |
# File 'lib/ast/crispr.rb', line 1621 def report data = to_h selector_kind_family = KNOWN_SELECTOR_KINDS[selector_kind]&.fetch(:family, nil) comment_region_family = comment_region.nil? ? :none : KNOWN_COMMENT_REGIONS[comment_region]&.fetch(:family, nil) owner_selector_family = owner_selector == :heading_sections ? :section : structure_profile.owner_selector_family known_comment_region = !comment_region.nil? && KNOWN_COMMENT_REGIONS.key?(comment_region) data.merge!( owner_selector_family: owner_selector_family || :unknown, known_owner_selector: structure_profile.known_owner_selector?, selector_kind_family: selector_kind_family || :unknown, known_selector_kind: KNOWN_SELECTOR_KINDS.key?(selector_kind), selection_intent_family: COMPAT_SELECTION_INTENT_FAMILIES.fetch(selection_intent, :unknown), known_selection_intent: COMPAT_SELECTION_INTENT_FAMILIES.key?(selection_intent), comment_region_family: comment_region_family || :unknown, known_comment_region: known_comment_region, comment_anchored: known_comment_region || selector_kind_family == :comment_anchor || COMPAT_SELECTION_INTENT_FAMILIES[selection_intent] == :comment ) stringified_report(data) end |
#selection_intent_family ⇒ Object
539 540 541 |
# File 'lib/ast/crispr.rb', line 539 def selection_intent_family &.fetch(:family, nil) end |
#selection_intent_metadata ⇒ Object
527 528 529 |
# File 'lib/ast/crispr.rb', line 527 def KNOWN_SELECTION_INTENTS[selection_intent]&.dup&.freeze end |
#to_h ⇒ Object
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/ast/crispr.rb', line 551 def to_h { owner_scope: owner_scope, owner_selector: structure_profile.owner_selector, owner_selector_family: structure_profile.owner_selector_family, selector_kind: selector_kind, selection_intent: selection_intent, selection_intent_family: selection_intent_family, known_selection_intent: known_selection_intent?, comment_region: comment_region, include_trailing_gap: include_trailing_gap, comment_anchored: comment_anchored?, metadata: } end |