Class: Ukiryu::Extractors::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/extractors/extractor.rb

Overview

Main extractor class that orchestrates extraction strategies

Tries multiple extraction strategies in order:

  1. Native flag extraction (–ukiryu-definition)

  2. Help parsing (–help output)

Examples:

Extract definition from a tool

result = Ukiryu::Extractor.extract(:git)
if result[:success]
  puts result[:yaml]
else
  puts "Failed: #{result[:error]}"
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_name, options = {}) ⇒ Extractor

Initialize the extractor

Parameters:

  • tool_name (String, Symbol)

    the tool name

  • options (Hash) (defaults to: {})

    extraction options



36
37
38
39
# File 'lib/ukiryu/extractors/extractor.rb', line 36

def initialize(tool_name, options = {})
  @tool_name = tool_name
  @options = options
end

Class Method Details

.extract(tool_name, options = {}) ⇒ Hash

Extract definition from a tool

Tries multiple extraction strategies in order until one succeeds.

Parameters:

  • tool_name (String, Symbol)

    the tool name

  • options (Hash) (defaults to: {})

    extraction options

Options Hash (options):

  • :method (Symbol)

    specific method to use (:native, :help, :auto)

  • :verbose (Boolean)

    enable verbose output

Returns:

  • (Hash)

    result with :success, :yaml, :method, :error keys



28
29
30
# File 'lib/ukiryu/extractors/extractor.rb', line 28

def self.extract(tool_name, options = {})
  new(tool_name, options).extract
end

Instance Method Details

#extractHash

Extract definition using available strategies

Returns:

  • (Hash)

    result with :success, :yaml, :method, :error keys



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ukiryu/extractors/extractor.rb', line 44

def extract
  method = @options[:method] || :auto

  case method
  when :auto
    extract_auto
  when :native
    extract_with_native
  when :help
    extract_with_help
  else
    {
      success: false,
      error: "Unknown extraction method: #{method}",
      method: nil,
      yaml: nil
    }
  end
end