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

Inherits:
Reference
  • Object
show all
Defined in:
lib/card/content/chunk/query_reference.rb

Overview

handle chunks of CQL query content that refer to other cards

Constant Summary collapse

QUERY_KEYWORDS =
::Set.new(
  (
    Query::MODIFIERS.keys +
    Query::OPERATORS.keys +
    Query.attributes.keys +
    Query::CONJUNCTIONS.keys +
    %w[desc asc count]
  ).map(&:to_s)
)

Instance Attribute Summary

Attributes inherited from Reference

#name, #referee_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Reference

#referee_card, #referee_raw_name

Class Method Details

.full_match(content, prefix) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/card/content/chunk/query_reference.rb', line 58

def full_match content, prefix
  # matches cardnames that are not keywords
  # FIXME: would not match cardnames that are keywords
  match, offset = super
  return if !match || keyword?(match[1])

  [match, offset]
end

.keyword?(str) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/card/content/chunk/query_reference.rb', line 67

def keyword? str
  return false unless str

  QUERY_KEYWORDS.include?(str.tr(" ", "_").downcase)
end

Instance Method Details

#inspectObject



82
83
84
# File 'lib/card/content/chunk/query_reference.rb', line 82

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

#interpret(match, _content) ⇒ Object



74
75
76
# File 'lib/card/content/chunk/query_reference.rb', line 74

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

#process_chunkObject



78
79
80
# File 'lib/card/content/chunk/query_reference.rb', line 78

def process_chunk
  @process_chunk ||= @text
end

#reference_codeObject



91
92
93
# File 'lib/card/content/chunk/query_reference.rb', line 91

def reference_code
  "Q" # for "Query"
end

#swap_name(old_name, new_name) ⇒ Object



86
87
88
89
# File 'lib/card/content/chunk/query_reference.rb', line 86

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