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

Inherits:
Reference show all
Defined in:
card-mod-content/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

Attributes inherited from Abstract

#text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Reference

#referee_card, #referee_raw_name

Methods inherited from Abstract

#as_json, #burn_after_reading, #burn_read, #card, context_ok?, #format, full_re, #initialize, #result, #to_s

Constructor Details

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

Class Method Details

.full_match(content, prefix) ⇒ Object



56
57
58
59
60
61
62
63
# File 'card-mod-content/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 'card-mod-content/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 'card-mod-content/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 'card-mod-content/lib/card/content/chunk/query_reference.rb', line 72

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

#process_chunkObject



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

def process_chunk
  @process_chunk ||= @text
end

#reference_codeObject



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

def reference_code
  "Q" # for "Query"
end

#replace_reference(old_name, new_name) ⇒ Object



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

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