Class: Card::Content::Chunk::QueryReference
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_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_name_from_rendered, #render_obj, #replace_name_reference
Methods inherited from Abstract
#as_json, #card, context_ok?, #format, full_re, #initialize, #result, #to_s
Class Method Details
.full_match(content, prefix) ⇒ Object
55
56
57
58
59
60
61
|
# File 'mod/core/chunk/query_reference.rb', line 55
def full_match content, prefix
match, offset = super(content, prefix)
return if !match || keyword?(match[1])
[match, offset]
end
|
.keyword?(str) ⇒ Boolean
63
64
65
66
|
# File 'mod/core/chunk/query_reference.rb', line 63
def keyword? str
return unless str
QUERY_KEYWORDS.include?(str.tr(" ", "_").downcase)
end
|
Instance Method Details
#inspect ⇒ Object
77
78
79
|
# File 'mod/core/chunk/query_reference.rb', line 77
def inspect
"<##{self.class}:n[#{@name}] p[#{@process_chunk}] txt:#{@text}>"
end
|
#interpret(match, _content) ⇒ Object
69
70
71
|
# File 'mod/core/chunk/query_reference.rb', line 69
def interpret match, _content
@name = match[1]
end
|
#process_chunk ⇒ Object
73
74
75
|
# File 'mod/core/chunk/query_reference.rb', line 73
def process_chunk
@process_chunk ||= @text
end
|
#reference_code ⇒ Object
86
87
88
|
# File 'mod/core/chunk/query_reference.rb', line 86
def reference_code
"Q" end
|
#replace_reference(old_name, new_name) ⇒ Object
81
82
83
84
|
# File 'mod/core/chunk/query_reference.rb', line 81
def replace_reference old_name, new_name
replace_name_reference old_name, new_name
@text = "\"#{@name}\""
end
|