Module: Nukitori

Defined in:
lib/nukitori.rb,
lib/nukitori/version.rb,
lib/nukitori/chat_factory.rb,
lib/nukitori/llm_extractor.rb,
lib/nukitori/response_parser.rb,
lib/nukitori/schema_extractor.rb,
lib/nukitori/schema_generator.rb,
lib/nukitori/html_preprocessor.rb

Defined Under Namespace

Classes: ChatFactory, HtmlPreprocessor, LlmExtractor, ResponseParser, SchemaExtractor, SchemaGenerator

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.call(html, schema_path = nil, model: nil, prefix: nil, &block) ⇒ Hash

Main entry point - callable as Nukitori(html, 'schema.json') { schema }

Examples:

With schema caching (recommended for scraping similar pages)

data = Nukitori(html, 'repos_schema.json') do
  array :repos do
    object do
      string :name
      string :url
    end
  end
end

With custom model

data = Nukitori(html, 'repos_schema.json', model: 'gpt-5.2') do
  string :title
end

AI-only mode (no schema, calls LLM each time)

data = Nukitori(html) do
  array :products do
    object do
      string :title
      number :price
    end
  end
end

AI-only mode with custom model

data = Nukitori(html, model: 'claude-sonnet-4') do
  string :title
end

Parameters:

  • html (String, Nokogiri::HTML::Document) —

    HTML content or Nokogiri doc

  • schema_path (String, nil) (defaults to: nil) —

    Path to cache extraction schema (optional)

  • model (String, nil) (defaults to: nil) —

    LLM model to use (overrides default_model)

  • block (Proc) —

    Schema definition block

Returns:

  • (Hash) —

    Extracted data

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
77
# File 'lib/nukitori.rb', line 69

def call(html, schema_path = nil, model: nil, prefix: nil, &block)
  raise ArgumentError, 'Block required for schema definition' unless block_given?

  if schema_path
    extract_with_schema(html, schema_path, model:, prefix:, &block)
  else
    LlmExtractor.extract(html, model:, &block)
  end
end

.configure ⇒ Object

Configure RubyLLM through Nukitori

Examples:

Nukitori.configure do |config|
  config.default_model = 'gpt-5.2'
  config.openai_api_key = ENV['OPENAI_API_KEY']
end


25
26
27
28
29
# File 'lib/nukitori.rb', line 25

def configure
  RubyLLM.configure do |config|
    yield config if block_given?
  end
end