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

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

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



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

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

  [match, offset]
end

.keyword?(str) ⇒ Boolean

Returns:

  • (Boolean)


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

def keyword? str
  return unless str

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

Instance Method Details

#inspectObject



80
81
82
# File 'lib/card/content/chunk/query_reference.rb', line 80

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

#interpret(match, _content) ⇒ Object



72
73
74
# File 'lib/card/content/chunk/query_reference.rb', line 72

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

#process_chunkObject



76
77
78
# File 'lib/card/content/chunk/query_reference.rb', line 76

def process_chunk
  @process_chunk ||= @text
end

#reference_codeObject



89
90
91
# File 'lib/card/content/chunk/query_reference.rb', line 89

def reference_code
  "Q" # for "Query"
end

#swap_name(old_name, new_name) ⇒ Object



84
85
86
87
# File 'lib/card/content/chunk/query_reference.rb', line 84

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