Class: Typst::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/query.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#compiled, #options

Instance Method Summary collapse

Methods inherited from Base

#compile, from_s, from_zip, #query, #typst_args, #typst_pdf_args, #typst_png_args, #with_dependencies, #with_font_paths, #with_fonts, #with_inputs, #with_root

Constructor Details

#initialize(selector, input, field: nil, one: false, format: "json", root: ".", font_paths: [], resource_path: ".", ignore_system_fonts: false, sys_inputs: {}) ⇒ Query

Returns a new instance of Query.



5
6
7
8
# File 'lib/query.rb', line 5

def initialize(selector, input, field: nil, one: false, format: "json", root: ".", font_paths: [], resource_path: ".", ignore_system_fonts: false, sys_inputs: {})
  self.format = format
  @result = Typst::_query(selector, field, one, format, input, root, font_paths, resource_path, ignore_system_fonts, sys_inputs)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/query.rb', line 3

def format
  @format
end

Instance Method Details

#result(raw: false) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/query.rb', line 10

def result(raw: false)
  case raw || format
    when "json" then JSON(@result)
    when "yaml" then YAML::safe_load(@result)
    else @result
  end
end

#to_sObject



18
19
20
# File 'lib/query.rb', line 18

def to_s
  @result
end