Class: MQ::Query
- Inherits:
-
Object
- Object
- MQ::Query
- Defined in:
- lib/mq/query.rb
Overview
Programmatic query builder for constructing mq queries in Ruby.
Class Method Summary collapse
- .align ⇒ Object
- .alt ⇒ Object
- .blockquote ⇒ Object
- .checked ⇒ Object
-
.code ⇒ Object
Block element selectors.
-
.code_inline ⇒ Object
Inline element selectors.
- .column ⇒ Object
- .definition ⇒ Object
- .delete ⇒ Object
- .depth ⇒ Object
- .done ⇒ Object
- .emphasis ⇒ Object
- .fence ⇒ Object
- .footnote ⇒ Object
- .footnote_ref ⇒ Object
-
.heading ⇒ Object
Generic heading (any level).
- .hr ⇒ Object
- .html ⇒ Object
- .image ⇒ Object
- .image_ref ⇒ Object
- .lang ⇒ Object
- .level ⇒ Object
- .line_break ⇒ Object
- .link ⇒ Object
- .link_ref ⇒ Object
-
.list ⇒ Object
--- List selector ---.
-
.list_at(n) ⇒ Object
List item at a specific index: .[n].
- .math ⇒ Object
- .math_inline ⇒ Object
- .mdx_flow_expression ⇒ Object
- .mdx_js_esm ⇒ Object
-
.mdx_jsx_flow_element ⇒ Object
--- MDX selectors ---.
- .mdx_jsx_text_element ⇒ Object
- .mdx_text_expression ⇒ Object
- .meta ⇒ Object
- .node_values ⇒ Object
- .ordered ⇒ Object
- .paragraph ⇒ Object
-
.property(key) ⇒ Object
Dict property selector: ."key".
- .rand ⇒ Object
- .rand_int(min, max) ⇒ Object
-
.random_string(len, charset) ⇒ Object
Returns a random string of
lencharacters drawn (with replacement) fromcharset. -
.recursive ⇒ Object
Recursive / deep selector (..).
- .row ⇒ Object
-
.select(filter = nil) { ... } ⇒ Query
Class-level select (no leading selector).
- .strong ⇒ Object
- .table ⇒ Object
- .table_align ⇒ Object
-
.table_cell(r, c) ⇒ Object
A specific cell: .[row][col].
-
.table_col(n) ⇒ Object
All cells in a specific column: .[][n].
-
.table_row(n) ⇒ Object
All cells in a specific row: .[n][].
-
.task ⇒ Object
Task list selectors.
- .text ⇒ Object
- .to_markdown ⇒ Object
- .to_text ⇒ Object
- .todo ⇒ Object
- .toml ⇒ Object
- .url ⇒ Object
-
.uuid ⇒ Object
--- Value generators (usable as query starting points) ---.
- .uuid_v4 ⇒ Object
- .uuid_v7 ⇒ Object
-
.value ⇒ Object
--- Attribute selectors (as standalone starting points) ---.
- .yaml ⇒ Object
Instance Method Summary collapse
- #abs ⇒ Object
- #add(other) ⇒ Object
- #align ⇒ Object
- #alt ⇒ Object
- #ascii_downcase ⇒ Object
- #ascii_upcase ⇒ Object
- #attr(name) ⇒ Object
- #base64 ⇒ Object
- #base64d ⇒ Object
- #base64url ⇒ Object
- #base64urld ⇒ Object
- #basename ⇒ Object
- #capture(pattern) ⇒ Object
- #ceil ⇒ Object
- #checked ⇒ Object
- #children ⇒ Object
- #coalesce(default) ⇒ Object
- #column ⇒ Object
- #compact ⇒ Object
-
#css(selector) ⇒ Object
Returns the outer HTML of every element in the current (raw) HTML string matching the CSS
selector, as an array of strings. -
#css_attr(selector, name) ⇒ Object
Returns the value of attribute
namefor every element in the current (raw) HTML string matching the CSSselector, as an array. -
#css_text(selector) ⇒ Object
Returns the text content of every element in the current (raw) HTML string matching the CSS
selector, as an array of strings. - #debug ⇒ Object
- #del(value) ⇒ Object
- #depth ⇒ Object
- #dirname ⇒ Object
- #downcase ⇒ Object
- #empty ⇒ Object
- #entries ⇒ Object
- #exp ⇒ Object
- #explode ⇒ Object
- #extname ⇒ Object
- #fence ⇒ Object
- #first ⇒ Object
- #flatten ⇒ Object
- #floor ⇒ Object
- #from_hex ⇒ Object
- #get(key) ⇒ Object
-
#get_path(path) ⇒ Object
Retrieves a nested value by following an array of keys/indices.
- #get_title ⇒ Object
- #get_url ⇒ Object
-
#glob_match(path) ⇒ Object
Treats the current string as a glob pattern (e.g. ".md", "docs/**/.rs") and returns whether it matches
path. - #gsub(pattern, replacement) ⇒ Object
- #html_escape ⇒ Object
- #html_unescape ⇒ Object
- #ident ⇒ Object
- #implode ⇒ Object
- #index(value) ⇒ Object
-
#initialize(expr = "") ⇒ Query
constructor
A new instance of Query.
- #insert(idx, val) ⇒ Object
- #intern ⇒ Object
- #is_nan ⇒ Object
- #item_index ⇒ Object
- #join(separator) ⇒ Object
- #keys ⇒ Object
- #label ⇒ Object
- #lang ⇒ Object
- #last ⇒ Object
- #len ⇒ Object
- #length ⇒ Object
- #level ⇒ Object
- #limit(n) ⇒ Object
- #ln ⇒ Object
- #log10 ⇒ Object
- #ltrim ⇒ Object
-
#map(filter = nil) { ... } ⇒ Query
Append a map() transformation.
- #max(other) ⇒ Object
- #md5 ⇒ Object
- #mdx_name ⇒ Object
- #meta ⇒ Object
- #min(other) ⇒ Object
- #negate_val ⇒ Object
- #nth(n) ⇒ Object
- #ordered ⇒ Object
- #path_join(other) ⇒ Object
-
#paths ⇒ Object
Returns an array of leaf-path arrays for the current value.
- #pow(n) ⇒ Object
-
#property(key) ⇒ Object
Access a dict property by key (generates ."key" selector).
- #rand ⇒ Object
- #rand_int(min, max) ⇒ Object
- #range(n) ⇒ Object
- #repeat(n) ⇒ Object
- #replace(from, to) ⇒ Object
- #reverse ⇒ Object
- #rindex(value) ⇒ Object
- #round ⇒ Object
- #row ⇒ Object
- #rtrim ⇒ Object
- #sample(n) ⇒ Object
- #sanitize_html ⇒ Object
- #scan(pattern) ⇒ Object
-
#select(filter = nil) { ... } ⇒ Query
Append a select() filter.
- #set(key, val) ⇒ Object
- #set_attr(name, val) ⇒ Object
- #set_check(val) ⇒ Object
- #set_code_block_lang(lang) ⇒ Object
- #set_list_ordered(val) ⇒ Object
-
#set_path(path, new_value) ⇒ Object
Sets a nested value by following an array of keys/indices, creating missing intermediate dicts/arrays automatically.
- #set_ref(ref) ⇒ Object
- #sha256 ⇒ Object
- #sha512 ⇒ Object
- #shuffle ⇒ Object
- #slice(start, stop) ⇒ Object
- #sort ⇒ Object
- #split(separator) ⇒ Object
- #sqrt ⇒ Object
- #stem ⇒ Object
- #strip_tags ⇒ Object
- #test(pattern) ⇒ Object
- #title ⇒ Object
- #to_array ⇒ Object
- #to_boolean ⇒ Object
- #to_bytes ⇒ Object
-
#to_code(lang = nil) ⇒ Object
Convert current value to a code block with the given language.
- #to_code_inline ⇒ Object
- #to_em ⇒ Object
-
#to_h(depth) ⇒ Object
Convert current value to a heading of the given depth (1-6).
- #to_hex ⇒ Object
- #to_hex_str ⇒ Object
- #to_hr ⇒ Object
- #to_html ⇒ Object
-
#to_image(url, img_alt = nil, img_title = "") ⇒ Object
Create an image node.
-
#to_link(url, text = nil, link_title = "") ⇒ Object
Create a link node.
- #to_markdown ⇒ Object
- #to_markdown_string ⇒ Object
- #to_math ⇒ Object
- #to_math_inline ⇒ Object
-
#to_md_list(list_level) ⇒ Object
Convert current value to a list item at the given nesting level.
-
#to_md_name(node_name) ⇒ Object
Convert current value to a markdown element with the given node name.
-
#to_md_table_cell(content, r, c) ⇒ Object
Build a table cell with content, row index, and column index.
-
#to_md_table_row(*cells) ⇒ Object
Build a table row from the given cell values.
- #to_md_text ⇒ Object
- #to_mdx ⇒ Object
- #to_number ⇒ Object
-
#to_query ⇒ String
(also: #to_s)
Returns the mq query string.
- #to_string ⇒ Object
- #to_strong ⇒ Object
- #to_text ⇒ Object
-
#token_count(model = nil) ⇒ Object
Estimates (or, when mq was built with tiktoken support, exactly counts) the LLM tokens the current string would consume.
- #trim ⇒ Object
- #trunc ⇒ Object
- #truncate(len, ellipsis) ⇒ Object
-
#type ⇒ Object
--- Type / logic ---.
- #uniq ⇒ Object
- #upcase ⇒ Object
- #update(content) ⇒ Object
- #url ⇒ Object
- #url_decode ⇒ Object
- #url_encode ⇒ Object
- #utf8bytelen ⇒ Object
- #uuid ⇒ Object
- #uuid_v4 ⇒ Object
- #uuid_v7 ⇒ Object
-
#value ⇒ Object
Attribute selectors (access attributes of selected nodes) These generate attribute selector syntax (.url, .lang, etc.).
- #values ⇒ Object
- #word_wrap(width) ⇒ Object
-
#|(other) ⇒ Query
Pipe two queries together using the | operator.
Constructor Details
#initialize(expr = "") ⇒ Query
Returns a new instance of Query.
31 32 33 |
# File 'lib/mq/query.rb', line 31 def initialize(expr = "") @expr = expr.to_s end |
Class Method Details
.align ⇒ Object
518 |
# File 'lib/mq/query.rb', line 518 def align = new(".align") |
.alt ⇒ Object
511 |
# File 'lib/mq/query.rb', line 511 def alt = new(".alt") |
.blockquote ⇒ Object
439 |
# File 'lib/mq/query.rb', line 439 def blockquote = new(".blockquote") |
.checked ⇒ Object
515 |
# File 'lib/mq/query.rb', line 515 def checked = new(".checked") |
.code ⇒ Object
Block element selectors
437 |
# File 'lib/mq/query.rb', line 437 def code = new(".code") |
.code_inline ⇒ Object
Inline element selectors
457 |
# File 'lib/mq/query.rb', line 457 def code_inline = new(".code_inline") |
.column ⇒ Object
516 |
# File 'lib/mq/query.rb', line 516 def column = new(".column") |
.definition ⇒ Object
451 |
# File 'lib/mq/query.rb', line 451 def definition = new(".definition") |
.delete ⇒ Object
446 |
# File 'lib/mq/query.rb', line 446 def delete = new(".delete") |
.depth ⇒ Object
512 |
# File 'lib/mq/query.rb', line 512 def depth = new(".depth") |
.done ⇒ Object
467 |
# File 'lib/mq/query.rb', line 467 def done = new(".done") |
.emphasis ⇒ Object
445 |
# File 'lib/mq/query.rb', line 445 def emphasis = new(".emphasis") |
.fence ⇒ Object
509 |
# File 'lib/mq/query.rb', line 509 def fence = new(".fence") |
.footnote ⇒ Object
452 |
# File 'lib/mq/query.rb', line 452 def footnote = new(".footnote") |
.footnote_ref ⇒ Object
461 |
# File 'lib/mq/query.rb', line 461 def footnote_ref = new(".footnote_ref") |
.heading ⇒ Object
Generic heading (any level)
434 |
# File 'lib/mq/query.rb', line 434 def heading = new(".heading") |
.hr ⇒ Object
440 |
# File 'lib/mq/query.rb', line 440 def hr = new(".hr") |
.html ⇒ Object
450 |
# File 'lib/mq/query.rb', line 450 def html = new(".html") |
.image ⇒ Object
441 |
# File 'lib/mq/query.rb', line 441 def image = new(".image") |
.image_ref ⇒ Object
460 |
# File 'lib/mq/query.rb', line 460 def image_ref = new(".image_ref") |
.lang ⇒ Object
507 |
# File 'lib/mq/query.rb', line 507 def lang = new(".lang") |
.level ⇒ Object
513 |
# File 'lib/mq/query.rb', line 513 def level = new(".level") |
.line_break ⇒ Object
462 |
# File 'lib/mq/query.rb', line 462 def line_break = new(".break") |
.link ⇒ Object
442 |
# File 'lib/mq/query.rb', line 442 def link = new(".link") |
.link_ref ⇒ Object
459 |
# File 'lib/mq/query.rb', line 459 def link_ref = new(".link_ref") |
.list ⇒ Object
--- List selector ---
470 |
# File 'lib/mq/query.rb', line 470 def list = new(".[]") |
.list_at(n) ⇒ Object
List item at a specific index: .[n]
473 474 475 |
# File 'lib/mq/query.rb', line 473 def list_at(n) new(".[#{n}]") end |
.math ⇒ Object
447 |
# File 'lib/mq/query.rb', line 447 def math = new(".math") |
.math_inline ⇒ Object
458 |
# File 'lib/mq/query.rb', line 458 def math_inline = new(".math_inline") |
.mdx_flow_expression ⇒ Object
498 |
# File 'lib/mq/query.rb', line 498 def mdx_flow_expression = new(".mdx_flow_expression") |
.mdx_js_esm ⇒ Object
499 |
# File 'lib/mq/query.rb', line 499 def mdx_js_esm = new(".mdx_js_esm") |
.mdx_jsx_flow_element ⇒ Object
--- MDX selectors ---
495 |
# File 'lib/mq/query.rb', line 495 def mdx_jsx_flow_element = new(".mdx_jsx_flow_element") |
.mdx_jsx_text_element ⇒ Object
497 |
# File 'lib/mq/query.rb', line 497 def mdx_jsx_text_element = new(".mdx_jsx_text_element") |
.mdx_text_expression ⇒ Object
496 |
# File 'lib/mq/query.rb', line 496 def mdx_text_expression = new(".mdx_text_expression") |
.meta ⇒ Object
508 |
# File 'lib/mq/query.rb', line 508 def = new(".meta") |
.node_values ⇒ Object
506 |
# File 'lib/mq/query.rb', line 506 def node_values = new(".values") |
.ordered ⇒ Object
514 |
# File 'lib/mq/query.rb', line 514 def ordered = new(".ordered") |
.paragraph ⇒ Object
438 |
# File 'lib/mq/query.rb', line 438 def paragraph = new(".p") |
.property(key) ⇒ Object
Dict property selector: ."key"
521 522 523 |
# File 'lib/mq/query.rb', line 521 def property(key) new(".\"#{key}\"") end |
.rand ⇒ Object
542 |
# File 'lib/mq/query.rb', line 542 def rand = new("rand()") |
.rand_int(min, max) ⇒ Object
544 545 546 |
# File 'lib/mq/query.rb', line 544 def rand_int(min, max) new("rand_int(#{min}, #{max})") end |
.random_string(len, charset) ⇒ Object
Returns a random string of len characters drawn (with replacement)
from charset.
550 551 552 |
# File 'lib/mq/query.rb', line 550 def random_string(len, charset) new("random_string(#{len}, #{charset.inspect})") end |
.recursive ⇒ Object
Recursive / deep selector (..)
502 |
# File 'lib/mq/query.rb', line 502 def recursive = new("..") |
.row ⇒ Object
517 |
# File 'lib/mq/query.rb', line 517 def row = new(".row") |
.select(filter = nil) { ... } ⇒ Query
Class-level select (no leading selector)
530 531 532 533 |
# File 'lib/mq/query.rb', line 530 def select(filter = nil, &block) filter_str = new.send(:resolve_filter, filter, &block) new("select(#{filter_str})") end |
.strong ⇒ Object
444 |
# File 'lib/mq/query.rb', line 444 def strong = new(".strong") |
.table ⇒ Object
448 |
# File 'lib/mq/query.rb', line 448 def table = new(".table") |
.table_align ⇒ Object
449 |
# File 'lib/mq/query.rb', line 449 def table_align = new(".table_align") |
.table_cell(r, c) ⇒ Object
A specific cell: .[row][col]
490 491 492 |
# File 'lib/mq/query.rb', line 490 def table_cell(r, c) new(".[#{r}][#{c}]") end |
.table_col(n) ⇒ Object
All cells in a specific column: .[][n]
485 486 487 |
# File 'lib/mq/query.rb', line 485 def table_col(n) new(".[][#{n}]") end |
.table_row(n) ⇒ Object
All cells in a specific row: .[n][]
480 481 482 |
# File 'lib/mq/query.rb', line 480 def table_row(n) new(".[#{n}][]") end |
.task ⇒ Object
Task list selectors
465 |
# File 'lib/mq/query.rb', line 465 def task = new(".task") |
.text ⇒ Object
443 |
# File 'lib/mq/query.rb', line 443 def text = new(".text") |
.to_markdown ⇒ Object
536 |
# File 'lib/mq/query.rb', line 536 def to_markdown = new("to_markdown()") |
.to_text ⇒ Object
535 |
# File 'lib/mq/query.rb', line 535 def to_text = new("to_text()") |
.todo ⇒ Object
466 |
# File 'lib/mq/query.rb', line 466 def todo = new(".todo") |
.toml ⇒ Object
453 |
# File 'lib/mq/query.rb', line 453 def toml = new(".toml") |
.url ⇒ Object
510 |
# File 'lib/mq/query.rb', line 510 def url = new(".url") |
.uuid ⇒ Object
--- Value generators (usable as query starting points) ---
539 |
# File 'lib/mq/query.rb', line 539 def uuid = new("uuid()") |
.uuid_v4 ⇒ Object
540 |
# File 'lib/mq/query.rb', line 540 def uuid_v4 = new("uuid_v4()") |
.uuid_v7 ⇒ Object
541 |
# File 'lib/mq/query.rb', line 541 def uuid_v7 = new("uuid_v7()") |
.value ⇒ Object
--- Attribute selectors (as standalone starting points) ---
505 |
# File 'lib/mq/query.rb', line 505 def value = new(".value") |
.yaml ⇒ Object
454 |
# File 'lib/mq/query.rb', line 454 def yaml = new(".yaml") |
Instance Method Details
#abs ⇒ Object
196 |
# File 'lib/mq/query.rb', line 196 def abs = pipe_with("abs()") |
#add(other) ⇒ Object
78 79 80 |
# File 'lib/mq/query.rb', line 78 def add(other) pipe_with("add(#{other.inspect})") end |
#align ⇒ Object
330 |
# File 'lib/mq/query.rb', line 330 def align = pipe_with(".align") |
#alt ⇒ Object
319 |
# File 'lib/mq/query.rb', line 319 def alt = pipe_with(".alt") |
#ascii_downcase ⇒ Object
150 |
# File 'lib/mq/query.rb', line 150 def ascii_downcase = pipe_with("ascii_downcase()") |
#ascii_upcase ⇒ Object
151 |
# File 'lib/mq/query.rb', line 151 def ascii_upcase = pipe_with("ascii_upcase()") |
#attr(name) ⇒ Object
337 338 339 |
# File 'lib/mq/query.rb', line 337 def attr(name) pipe_with("attr(#{name.inspect})") end |
#base64 ⇒ Object
229 |
# File 'lib/mq/query.rb', line 229 def base64 = pipe_with("base64()") |
#base64d ⇒ Object
230 |
# File 'lib/mq/query.rb', line 230 def base64d = pipe_with("base64d()") |
#base64url ⇒ Object
231 |
# File 'lib/mq/query.rb', line 231 def base64url = pipe_with("base64url()") |
#base64urld ⇒ Object
232 |
# File 'lib/mq/query.rb', line 232 def base64urld = pipe_with("base64urld()") |
#basename ⇒ Object
249 |
# File 'lib/mq/query.rb', line 249 def basename = pipe_with("basename()") |
#capture(pattern) ⇒ Object
188 189 190 |
# File 'lib/mq/query.rb', line 188 def capture(pattern) pipe_with("capture(#{pattern.inspect})") end |
#ceil ⇒ Object
197 |
# File 'lib/mq/query.rb', line 197 def ceil = pipe_with("ceil()") |
#checked ⇒ Object
327 |
# File 'lib/mq/query.rb', line 327 def checked = pipe_with(".checked") |
#children ⇒ Object
93 |
# File 'lib/mq/query.rb', line 93 def children = pipe_with(".children") |
#coalesce(default) ⇒ Object
225 226 227 |
# File 'lib/mq/query.rb', line 225 def coalesce(default) pipe_with("coalesce(#{default.inspect})") end |
#column ⇒ Object
328 |
# File 'lib/mq/query.rb', line 328 def column = pipe_with(".column") |
#compact ⇒ Object
87 |
# File 'lib/mq/query.rb', line 87 def compact = pipe_with("compact") |
#css(selector) ⇒ Object
Returns the outer HTML of every element in the current (raw) HTML string
matching the CSS selector, as an array of strings.
266 267 268 |
# File 'lib/mq/query.rb', line 266 def css(selector) pipe_with("css(#{selector.inspect})") end |
#css_attr(selector, name) ⇒ Object
Returns the value of attribute name for every element in the current
(raw) HTML string matching the CSS selector, as an array.
278 279 280 |
# File 'lib/mq/query.rb', line 278 def css_attr(selector, name) pipe_with("css_attr(#{selector.inspect}, #{name.inspect})") end |
#css_text(selector) ⇒ Object
Returns the text content of every element in the current (raw) HTML
string matching the CSS selector, as an array of strings.
272 273 274 |
# File 'lib/mq/query.rb', line 272 def css_text(selector) pipe_with("css_text(#{selector.inspect})") end |
#debug ⇒ Object
223 |
# File 'lib/mq/query.rb', line 223 def debug = pipe_with("debug") |
#del(value) ⇒ Object
127 128 129 |
# File 'lib/mq/query.rb', line 127 def del(value) pipe_with("del(#{value.inspect})") end |
#depth ⇒ Object
323 |
# File 'lib/mq/query.rb', line 323 def depth = pipe_with(".depth") |
#dirname ⇒ Object
250 |
# File 'lib/mq/query.rb', line 250 def dirname = pipe_with("dirname()") |
#downcase ⇒ Object
148 |
# File 'lib/mq/query.rb', line 148 def downcase = pipe_with("downcase()") |
#empty ⇒ Object
84 |
# File 'lib/mq/query.rb', line 84 def empty = pipe_with("is_empty()") |
#entries ⇒ Object
92 |
# File 'lib/mq/query.rb', line 92 def entries = pipe_with("entries") |
#exp ⇒ Object
204 |
# File 'lib/mq/query.rb', line 204 def exp = pipe_with("exp()") |
#explode ⇒ Object
152 |
# File 'lib/mq/query.rb', line 152 def explode = pipe_with("explode()") |
#extname ⇒ Object
251 |
# File 'lib/mq/query.rb', line 251 def extname = pipe_with("extname()") |
#fence ⇒ Object
317 |
# File 'lib/mq/query.rb', line 317 def fence = pipe_with(".fence") |
#first ⇒ Object
82 |
# File 'lib/mq/query.rb', line 82 def first = pipe_with("first") |
#flatten ⇒ Object
89 |
# File 'lib/mq/query.rb', line 89 def flatten = pipe_with("flatten") |
#floor ⇒ Object
198 |
# File 'lib/mq/query.rb', line 198 def floor = pipe_with("floor()") |
#from_hex ⇒ Object
236 |
# File 'lib/mq/query.rb', line 236 def from_hex = pipe_with("from_hex()") |
#get(key) ⇒ Object
282 283 284 |
# File 'lib/mq/query.rb', line 282 def get(key) pipe_with("get(#{key.inspect})") end |
#get_path(path) ⇒ Object
Retrieves a nested value by following an array of keys/indices.
291 292 293 |
# File 'lib/mq/query.rb', line 291 def get_path(path) pipe_with("get_path(#{path.inspect})") end |
#get_title ⇒ Object
345 |
# File 'lib/mq/query.rb', line 345 def get_title = pipe_with("get_title") |
#get_url ⇒ Object
346 |
# File 'lib/mq/query.rb', line 346 def get_url = pipe_with("get_url") |
#glob_match(path) ⇒ Object
Treats the current string as a glob pattern (e.g. ".md", "docs/**/.rs")
and returns whether it matches path.
260 261 262 |
# File 'lib/mq/query.rb', line 260 def glob_match(path) pipe_with("glob_match(#{path.inspect})") end |
#gsub(pattern, replacement) ⇒ Object
176 177 178 |
# File 'lib/mq/query.rb', line 176 def gsub(pattern, replacement) pipe_with("gsub(#{pattern.inspect}, #{replacement.inspect})") end |
#html_escape ⇒ Object
157 |
# File 'lib/mq/query.rb', line 157 def html_escape = pipe_with("html_escape()") |
#html_unescape ⇒ Object
158 |
# File 'lib/mq/query.rb', line 158 def html_unescape = pipe_with("html_unescape()") |
#ident ⇒ Object
321 |
# File 'lib/mq/query.rb', line 321 def ident = pipe_with(".ident") |
#implode ⇒ Object
153 |
# File 'lib/mq/query.rb', line 153 def implode = pipe_with("implode()") |
#index(value) ⇒ Object
119 120 121 |
# File 'lib/mq/query.rb', line 119 def index(value) pipe_with("index(#{value.inspect})") end |
#insert(idx, val) ⇒ Object
131 132 133 |
# File 'lib/mq/query.rb', line 131 def insert(idx, val) pipe_with("insert(#{idx}, #{val.inspect})") end |
#intern ⇒ Object
156 |
# File 'lib/mq/query.rb', line 156 def intern = pipe_with("intern()") |
#is_nan ⇒ Object
206 |
# File 'lib/mq/query.rb', line 206 def is_nan = pipe_with("is_nan()") |
#item_index ⇒ Object
325 |
# File 'lib/mq/query.rb', line 325 def item_index = pipe_with(".index") |
#join(separator) ⇒ Object
99 100 101 |
# File 'lib/mq/query.rb', line 99 def join(separator) pipe_with("join(#{separator.inspect})") end |
#keys ⇒ Object
90 |
# File 'lib/mq/query.rb', line 90 def keys = pipe_with("keys") |
#label ⇒ Object
322 |
# File 'lib/mq/query.rb', line 322 def label = pipe_with(".label") |
#lang ⇒ Object
315 |
# File 'lib/mq/query.rb', line 315 def lang = pipe_with(".lang") |
#last ⇒ Object
83 |
# File 'lib/mq/query.rb', line 83 def last = pipe_with("last") |
#len ⇒ Object
75 |
# File 'lib/mq/query.rb', line 75 def len = pipe_with("len()") |
#length ⇒ Object
74 |
# File 'lib/mq/query.rb', line 74 def length = pipe_with("len()") |
#level ⇒ Object
324 |
# File 'lib/mq/query.rb', line 324 def level = pipe_with(".level") |
#limit(n) ⇒ Object
107 108 109 |
# File 'lib/mq/query.rb', line 107 def limit(n) pipe_with("take(#{n})") end |
#ln ⇒ Object
202 |
# File 'lib/mq/query.rb', line 202 def ln = pipe_with("ln()") |
#log10 ⇒ Object
203 |
# File 'lib/mq/query.rb', line 203 def log10 = pipe_with("log10()") |
#ltrim ⇒ Object
146 |
# File 'lib/mq/query.rb', line 146 def ltrim = pipe_with("ltrim()") |
#map(filter = nil) { ... } ⇒ Query
Append a map() transformation.
58 59 60 61 |
# File 'lib/mq/query.rb', line 58 def map(filter = nil, &block) filter_str = resolve_filter(filter, &block) pipe_with("map(#{filter_str})") end |
#max(other) ⇒ Object
216 217 218 |
# File 'lib/mq/query.rb', line 216 def max(other) pipe_with("max(#{other})") end |
#md5 ⇒ Object
233 |
# File 'lib/mq/query.rb', line 233 def md5 = pipe_with("md5()") |
#mdx_name ⇒ Object
331 |
# File 'lib/mq/query.rb', line 331 def mdx_name = pipe_with(".name") |
#meta ⇒ Object
316 |
# File 'lib/mq/query.rb', line 316 def = pipe_with(".meta") |
#min(other) ⇒ Object
212 213 214 |
# File 'lib/mq/query.rb', line 212 def min(other) pipe_with("min(#{other})") end |
#negate_val ⇒ Object
205 |
# File 'lib/mq/query.rb', line 205 def negate_val = pipe_with("negate()") |
#nth(n) ⇒ Object
103 104 105 |
# File 'lib/mq/query.rb', line 103 def nth(n) pipe_with("get(#{n})") end |
#ordered ⇒ Object
326 |
# File 'lib/mq/query.rb', line 326 def ordered = pipe_with(".ordered") |
#path_join(other) ⇒ Object
254 255 256 |
# File 'lib/mq/query.rb', line 254 def path_join(other) pipe_with("path_join(#{other.inspect})") end |
#paths ⇒ Object
Returns an array of leaf-path arrays for the current value.
302 303 304 |
# File 'lib/mq/query.rb', line 302 def paths pipe_with("paths()") end |
#pow(n) ⇒ Object
208 209 210 |
# File 'lib/mq/query.rb', line 208 def pow(n) pipe_with("pow(#{n})") end |
#property(key) ⇒ Object
Access a dict property by key (generates ."key" selector)
307 308 309 |
# File 'lib/mq/query.rb', line 307 def property(key) pipe_with(".\"#{key}\"") end |
#rand ⇒ Object
243 |
# File 'lib/mq/query.rb', line 243 def rand = pipe_with("rand()") |
#rand_int(min, max) ⇒ Object
245 246 247 |
# File 'lib/mq/query.rb', line 245 def rand_int(min, max) pipe_with("rand_int(#{min}, #{max})") end |
#range(n) ⇒ Object
111 112 113 |
# File 'lib/mq/query.rb', line 111 def range(n) pipe_with("range(#{n})") end |
#repeat(n) ⇒ Object
135 136 137 |
# File 'lib/mq/query.rb', line 135 def repeat(n) pipe_with("repeat(#{n})") end |
#replace(from, to) ⇒ Object
180 181 182 |
# File 'lib/mq/query.rb', line 180 def replace(from, to) pipe_with("replace(#{from.inspect}, #{to.inspect})") end |
#reverse ⇒ Object
85 |
# File 'lib/mq/query.rb', line 85 def reverse = pipe_with("reverse") |
#rindex(value) ⇒ Object
123 124 125 |
# File 'lib/mq/query.rb', line 123 def rindex(value) pipe_with("rindex(#{value.inspect})") end |
#round ⇒ Object
199 |
# File 'lib/mq/query.rb', line 199 def round = pipe_with("round()") |
#row ⇒ Object
329 |
# File 'lib/mq/query.rb', line 329 def row = pipe_with(".row") |
#rtrim ⇒ Object
147 |
# File 'lib/mq/query.rb', line 147 def rtrim = pipe_with("rtrim()") |
#sample(n) ⇒ Object
141 142 143 |
# File 'lib/mq/query.rb', line 141 def sample(n) pipe_with("sample(#{n})") end |
#sanitize_html ⇒ Object
159 |
# File 'lib/mq/query.rb', line 159 def sanitize_html = pipe_with("sanitize_html()") |
#scan(pattern) ⇒ Object
192 193 194 |
# File 'lib/mq/query.rb', line 192 def scan(pattern) pipe_with("scan(#{pattern.inspect})") end |
#select(filter = nil) { ... } ⇒ Query
Append a select() filter.
48 49 50 51 |
# File 'lib/mq/query.rb', line 48 def select(filter = nil, &block) filter_str = resolve_filter(filter, &block) pipe_with("select(#{filter_str})") end |
#set(key, val) ⇒ Object
286 287 288 |
# File 'lib/mq/query.rb', line 286 def set(key, val) pipe_with("set(#{key.inspect}, #{val.inspect})") end |
#set_attr(name, val) ⇒ Object
341 342 343 |
# File 'lib/mq/query.rb', line 341 def set_attr(name, val) pipe_with("set_attr(#{name.inspect}, #{val.inspect})") end |
#set_check(val) ⇒ Object
348 349 350 |
# File 'lib/mq/query.rb', line 348 def set_check(val) pipe_with("set_check(#{val})") end |
#set_code_block_lang(lang) ⇒ Object
356 357 358 |
# File 'lib/mq/query.rb', line 356 def set_code_block_lang(lang) pipe_with("set_code_block_lang(#{lang.inspect})") end |
#set_list_ordered(val) ⇒ Object
360 361 362 |
# File 'lib/mq/query.rb', line 360 def set_list_ordered(val) pipe_with("set_list_ordered(#{val})") end |
#set_path(path, new_value) ⇒ Object
Sets a nested value by following an array of keys/indices, creating missing intermediate dicts/arrays automatically.
297 298 299 |
# File 'lib/mq/query.rb', line 297 def set_path(path, new_value) pipe_with("set_path(#{path.inspect}, #{new_value.inspect})") end |
#set_ref(ref) ⇒ Object
352 353 354 |
# File 'lib/mq/query.rb', line 352 def set_ref(ref) pipe_with("set_ref(#{ref.inspect})") end |
#sha256 ⇒ Object
234 |
# File 'lib/mq/query.rb', line 234 def sha256 = pipe_with("sha256()") |
#sha512 ⇒ Object
235 |
# File 'lib/mq/query.rb', line 235 def sha512 = pipe_with("sha512()") |
#shuffle ⇒ Object
139 |
# File 'lib/mq/query.rb', line 139 def shuffle = pipe_with("shuffle()") |
#slice(start, stop) ⇒ Object
115 116 117 |
# File 'lib/mq/query.rb', line 115 def slice(start, stop) pipe_with("slice(#{start}, #{stop})") end |
#sort ⇒ Object
86 |
# File 'lib/mq/query.rb', line 86 def sort = pipe_with("sort") |
#split(separator) ⇒ Object
95 96 97 |
# File 'lib/mq/query.rb', line 95 def split(separator) pipe_with("split(#{separator.inspect})") end |
#sqrt ⇒ Object
201 |
# File 'lib/mq/query.rb', line 201 def sqrt = pipe_with("sqrt()") |
#stem ⇒ Object
252 |
# File 'lib/mq/query.rb', line 252 def stem = pipe_with("stem()") |
#strip_tags ⇒ Object
160 |
# File 'lib/mq/query.rb', line 160 def = pipe_with("strip_tags()") |
#test(pattern) ⇒ Object
184 185 186 |
# File 'lib/mq/query.rb', line 184 def test(pattern) pipe_with("test(#{pattern.inspect})") end |
#title ⇒ Object
320 |
# File 'lib/mq/query.rb', line 320 def title = pipe_with(".title") |
#to_array ⇒ Object
70 |
# File 'lib/mq/query.rb', line 70 def to_array = pipe_with("to_array()") |
#to_boolean ⇒ Object
69 |
# File 'lib/mq/query.rb', line 69 def to_boolean = pipe_with("to_boolean()") |
#to_bytes ⇒ Object
71 |
# File 'lib/mq/query.rb', line 71 def to_bytes = pipe_with("to_bytes()") |
#to_code(lang = nil) ⇒ Object
Convert current value to a code block with the given language.
365 366 367 |
# File 'lib/mq/query.rb', line 365 def to_code(lang = nil) lang ? pipe_with("to_code(#{lang.inspect})") : pipe_with("to_code(null)") end |
#to_code_inline ⇒ Object
369 |
# File 'lib/mq/query.rb', line 369 def to_code_inline = pipe_with("to_code_inline()") |
#to_em ⇒ Object
401 |
# File 'lib/mq/query.rb', line 401 def to_em = pipe_with("to_em()") |
#to_h(depth) ⇒ Object
Convert current value to a heading of the given depth (1-6).
372 373 374 |
# File 'lib/mq/query.rb', line 372 def to_h(depth) pipe_with("to_h(#{depth})") end |
#to_hex ⇒ Object
237 |
# File 'lib/mq/query.rb', line 237 def to_hex = pipe_with("to_hex()") |
#to_hex_str ⇒ Object
238 |
# File 'lib/mq/query.rb', line 238 def to_hex_str = pipe_with("to_hex()") |
#to_hr ⇒ Object
376 |
# File 'lib/mq/query.rb', line 376 def to_hr = pipe_with("to_hr()") |
#to_html ⇒ Object
66 |
# File 'lib/mq/query.rb', line 66 def to_html = pipe_with("to_html()") |
#to_image(url, img_alt = nil, img_title = "") ⇒ Object
Create an image node. With all three args no auto-prepend occurs. With two args the current value becomes the alt text.
390 391 392 393 394 395 396 |
# File 'lib/mq/query.rb', line 390 def to_image(url, img_alt = nil, img_title = "") if img_alt pipe_with("to_image(#{url.inspect}, #{img_alt.inspect}, #{img_title.inspect})") else pipe_with("to_image(#{url.inspect}, #{img_title.inspect})") end end |
#to_link(url, text = nil, link_title = "") ⇒ Object
Create a link node. With all three args no auto-prepend occurs. With two args the current value becomes the link text.
380 381 382 383 384 385 386 |
# File 'lib/mq/query.rb', line 380 def to_link(url, text = nil, link_title = "") if text pipe_with("to_link(#{url.inspect}, #{text.inspect}, #{link_title.inspect})") else pipe_with("to_link(#{url.inspect}, #{link_title.inspect})") end end |
#to_markdown ⇒ Object
64 |
# File 'lib/mq/query.rb', line 64 def to_markdown = pipe_with("to_markdown()") |
#to_markdown_string ⇒ Object
72 |
# File 'lib/mq/query.rb', line 72 def to_markdown_string = pipe_with("to_markdown_string()") |
#to_math ⇒ Object
398 |
# File 'lib/mq/query.rb', line 398 def to_math = pipe_with("to_math()") |
#to_math_inline ⇒ Object
399 |
# File 'lib/mq/query.rb', line 399 def to_math_inline = pipe_with("to_math_inline()") |
#to_md_list(list_level) ⇒ Object
Convert current value to a list item at the given nesting level.
405 406 407 |
# File 'lib/mq/query.rb', line 405 def to_md_list(list_level) pipe_with("to_md_list(#{list_level})") end |
#to_md_name(node_name) ⇒ Object
Convert current value to a markdown element with the given node name.
410 411 412 |
# File 'lib/mq/query.rb', line 410 def to_md_name(node_name) pipe_with("to_md_name(#{node_name.inspect})") end |
#to_md_table_cell(content, r, c) ⇒ Object
Build a table cell with content, row index, and column index.
420 421 422 |
# File 'lib/mq/query.rb', line 420 def to_md_table_cell(content, r, c) pipe_with("to_md_table_cell(#{content.inspect}, #{r}, #{c})") end |
#to_md_table_row(*cells) ⇒ Object
Build a table row from the given cell values.
415 416 417 |
# File 'lib/mq/query.rb', line 415 def to_md_table_row(*cells) pipe_with("to_md_table_row(#{cells.map(&:inspect).join(', ')})") end |
#to_md_text ⇒ Object
402 |
# File 'lib/mq/query.rb', line 402 def to_md_text = pipe_with("to_md_text()") |
#to_mdx ⇒ Object
65 |
# File 'lib/mq/query.rb', line 65 def to_mdx = pipe_with("to_mdx()") |
#to_number ⇒ Object
68 |
# File 'lib/mq/query.rb', line 68 def to_number = pipe_with("to_number()") |
#to_query ⇒ String Also known as: to_s
Returns the mq query string.
426 |
# File 'lib/mq/query.rb', line 426 def to_query = @expr |
#to_string ⇒ Object
67 |
# File 'lib/mq/query.rb', line 67 def to_string = pipe_with("to_string()") |
#to_strong ⇒ Object
400 |
# File 'lib/mq/query.rb', line 400 def to_strong = pipe_with("to_strong()") |
#to_text ⇒ Object
63 |
# File 'lib/mq/query.rb', line 63 def to_text = pipe_with("to_text()") |
#token_count(model = nil) ⇒ Object
Estimates (or, when mq was built with tiktoken support, exactly counts) the
LLM tokens the current string would consume. model is optional.
172 173 174 |
# File 'lib/mq/query.rb', line 172 def token_count(model = nil) model ? pipe_with("token_count(#{model.inspect})") : pipe_with("token_count()") end |
#trim ⇒ Object
145 |
# File 'lib/mq/query.rb', line 145 def trim = pipe_with("trim()") |
#trunc ⇒ Object
200 |
# File 'lib/mq/query.rb', line 200 def trunc = pipe_with("trunc()") |
#truncate(len, ellipsis) ⇒ Object
166 167 168 |
# File 'lib/mq/query.rb', line 166 def truncate(len, ellipsis) pipe_with("truncate(#{len}, #{ellipsis.inspect})") end |
#type ⇒ Object
--- Type / logic ---
222 |
# File 'lib/mq/query.rb', line 222 def type = pipe_with("type") |
#uniq ⇒ Object
88 |
# File 'lib/mq/query.rb', line 88 def uniq = pipe_with("uniq") |
#upcase ⇒ Object
149 |
# File 'lib/mq/query.rb', line 149 def upcase = pipe_with("upcase()") |
#update(content) ⇒ Object
333 334 335 |
# File 'lib/mq/query.rb', line 333 def update(content) pipe_with("update(#{content.inspect})") end |
#url ⇒ Object
318 |
# File 'lib/mq/query.rb', line 318 def url = pipe_with(".url") |
#url_decode ⇒ Object
155 |
# File 'lib/mq/query.rb', line 155 def url_decode = pipe_with("url_decode()") |
#url_encode ⇒ Object
154 |
# File 'lib/mq/query.rb', line 154 def url_encode = pipe_with("url_encode()") |
#utf8bytelen ⇒ Object
76 |
# File 'lib/mq/query.rb', line 76 def utf8bytelen = pipe_with("utf8bytelen()") |
#uuid ⇒ Object
240 |
# File 'lib/mq/query.rb', line 240 def uuid = pipe_with("uuid()") |
#uuid_v4 ⇒ Object
241 |
# File 'lib/mq/query.rb', line 241 def uuid_v4 = pipe_with("uuid_v4()") |
#uuid_v7 ⇒ Object
242 |
# File 'lib/mq/query.rb', line 242 def uuid_v7 = pipe_with("uuid_v7()") |
#value ⇒ Object
Attribute selectors (access attributes of selected nodes) These generate attribute selector syntax (.url, .lang, etc.)
314 |
# File 'lib/mq/query.rb', line 314 def value = pipe_with(".value") |
#values ⇒ Object
91 |
# File 'lib/mq/query.rb', line 91 def values = pipe_with("values") |
#word_wrap(width) ⇒ Object
162 163 164 |
# File 'lib/mq/query.rb', line 162 def word_wrap(width) pipe_with("word_wrap(#{width})") end |
#|(other) ⇒ Query
Pipe two queries together using the | operator.
39 40 41 |
# File 'lib/mq/query.rb', line 39 def |(other) self.class.new("#{@expr} | #{other.to_query}") end |