Class: Card::Content::Chunk::QueryReference

Inherits:
Reference show all
Defined in:
mod/core/chunk/query_reference.rb

Overview

This should find +Alfred+ in expressions like 1) "name":"Alfred" 2a) "name":["in","Alfred"] 3a) "plus_right":["Alfred"] but not in 2b) "content":"foo", "Alfred":"bar" 3b) "Toni"] ("Alfred" is an operator here) It's not possible to distinguish between 2a) and 2b) or 3a) and 3b) with a simple regex, hence we use a too general regex and check for query keywords after the match, which of course means that we don't find references with query keywords as name

Constant Summary collapse

QUERY_KEYWORDS =
::Set.new(
  (
    Card::Query::MODIFIERS.keys +
    Card::Query::OPERATORS.keys +
    Card::Query::ATTRIBUTES.keys +
    Card::Query::CONJUNCTIONS.keys +
    %w(desc asc count)
  ).map(&:to_name)
)

Instance Attribute Summary

Attributes inherited from Reference

#name, #referee_name

Attributes inherited from Abstract

#text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Reference

#referee_card, #render_obj, #replace_name_reference

Methods inherited from Abstract

#as_json, #card, context_ok?, #format, full_re, #initialize, #to_s

Constructor Details

This class inherits a constructor from Card::Content::Chunk::Abstract

Class Method Details

.full_match(content, prefix) ⇒ Object



55
56
57
58
59
# File 'mod/core/chunk/query_reference.rb', line 55

def full_match content, prefix
  match, offset = super(content, prefix)
  return unless match && !QUERY_KEYWORDS.include?(match[1].to_name)
  [match, offset]
end

Instance Method Details

#inspectObject



70
71
72
# File 'mod/core/chunk/query_reference.rb', line 70

def inspect
  "<##{self.class}:n[#{@name}] p[#{@process_chunk}] txt:#{@text}>"
end

#interpret(match, _content) ⇒ Object



62
63
64
# File 'mod/core/chunk/query_reference.rb', line 62

def interpret match, _content
  @name = match[1]
end

#process_chunkObject



66
67
68
# File 'mod/core/chunk/query_reference.rb', line 66

def process_chunk
  @process_chunk ||= @text
end

#reference_codeObject



79
80
81
# File 'mod/core/chunk/query_reference.rb', line 79

def reference_code
  "Q" # for "Query"
end

#replace_reference(old_name, new_name) ⇒ Object



74
75
76
77
# File 'mod/core/chunk/query_reference.rb', line 74

def replace_reference old_name, new_name
  replace_name_reference old_name, new_name
  @text = "\"#{@name}\""
end