Class: LlmDocsBuilder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_docs_builder/config.rb

Overview

Simple configuration loader for llm-docs-builder.yml files

Loads YAML configuration files and provides a simple interface for accessing configuration values. Automatically looks for config files in the current directory if none specified.

Examples:

Load default config file

config = LlmDocsBuilder::Config.new

Load specific config file

config = LlmDocsBuilder::Config.new('my-config.yml')

Access config values

config['base_url']        # => "https://myproject.io"
config.dig('output')      # => "llms.txt"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = nil) ⇒ Config

Initialize a new configuration loader

Parameters:

  • config_file (String, nil) (defaults to: nil)

    path to YAML config file, or nil to auto-find



29
30
31
32
# File 'lib/llm_docs_builder/config.rb', line 29

def initialize(config_file = nil)
  @config_file = config_file || find_config_file
  @data = load_config
end

Instance Attribute Details

#dataHash (readonly)

Returns the loaded configuration data.

Returns:

  • (Hash)

    the loaded configuration data



24
25
26
# File 'lib/llm_docs_builder/config.rb', line 24

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object?

Access configuration value by key

Parameters:

  • key (String, Symbol)

    configuration key

Returns:

  • (Object, nil)

    configuration value or nil if not found



38
39
40
# File 'lib/llm_docs_builder/config.rb', line 38

def [](key)
  data[key.to_s]
end

#dig(*keys) ⇒ Object?

Access nested configuration values

Parameters:

  • keys (Array<String, Symbol>)

    nested keys to access

Returns:

  • (Object, nil)

    configuration value or nil if not found



46
47
48
# File 'lib/llm_docs_builder/config.rb', line 46

def dig(*keys)
  data.dig(*keys.map(&:to_s))
end

#exists?Boolean

Check if a config file was found and exists

Returns:

  • (Boolean)

    true if config file exists, false otherwise



220
221
222
# File 'lib/llm_docs_builder/config.rb', line 220

def exists?
  @config_file && File.exist?(@config_file)
end

#merge_with_options(options) ⇒ Hash

Merge config file values with CLI options

CLI options take precedence over config file values. Config file provides defaults for any options not specified via CLI.

Parameters:

  • options (Hash)

    CLI options hash

Options Hash (options):

  • :docs (String)

    path to documentation directory or file

  • :base_url (String)

    base URL for expanding relative links

  • :title (String)

    project title

  • :description (String)

    project description

  • :body (String)

    additional body content

  • :output (String)

    output file path

  • :convert_urls (Boolean)

    convert HTML URLs to markdown format

  • :remove_comments (Boolean)

    remove HTML comments

  • :normalize_whitespace (Boolean)

    normalize whitespace

  • :remove_badges (Boolean)

    remove badge images

  • :remove_frontmatter (Boolean)

    remove YAML/TOML frontmatter

  • :verbose (Boolean)

    enable verbose output

  • :suffix (String)

    suffix for transformed files

  • :excludes (Array<String>)

    glob patterns for files to exclude

  • :bulk (Boolean)

    enable bulk transformation mode

  • :include_hidden (Boolean)

    include hidden files

  • :remove_code_examples (Boolean)

    remove code blocks

  • :remove_images (Boolean)

    remove image syntax

  • :simplify_links (Boolean)

    simplify link text

  • :remove_blockquotes (Boolean)

    remove blockquote formatting

  • :generate_toc (Boolean)

    generate table of contents

  • :custom_instruction (String)

    custom instruction text

  • :remove_stopwords (Boolean)

    remove common stopwords

  • :remove_duplicates (Boolean)

    remove duplicate paragraphs

  • :normalize_headings (Boolean)

    normalize heading hierarchy

  • :heading_separator (String)

    separator for heading paths

  • :include_metadata (Boolean)

    include metadata in output

  • :include_tokens (Boolean)

    include token counts

  • :include_timestamps (Boolean)

    include timestamps

  • :include_priority (Boolean)

    include priority metadata

  • :calculate_compression (Boolean)

    calculate compression ratios

  • :content (String)

    raw markdown content

  • :source_url (String)

    source URL for content

Returns:

  • (Hash)

    merged configuration with CLI overrides applied



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/llm_docs_builder/config.rb', line 90

def merge_with_options(options)
  # CLI options override config file, config file provides defaults
  {
    docs: if options.key?(:docs)
            options[:docs]
          else
            self['docs'] || '.'
          end,
    base_url: options[:base_url] || self['base_url'],
    title: options[:title] || self['title'],
    description: options[:description] || self['description'],
    body: options[:body] || self['body'],
    output: options[:output] || self['output'] || 'llms.txt',
    convert_urls: if options.key?(:convert_urls)
                    options[:convert_urls]
                  else
                    self['convert_urls'] || false
                  end,
    remove_comments: if options.key?(:remove_comments)
                       options[:remove_comments]
                     elsif !self['remove_comments'].nil?
                       self['remove_comments']
                     else
                       true
                     end,
    normalize_whitespace: if options.key?(:normalize_whitespace)
                            options[:normalize_whitespace]
                          elsif !self['normalize_whitespace'].nil?
                            self['normalize_whitespace']
                          else
                            true
                          end,
    remove_badges: if options.key?(:remove_badges)
                     options[:remove_badges]
                   elsif !self['remove_badges'].nil?
                     self['remove_badges']
                   else
                     true
                   end,
    remove_frontmatter: if options.key?(:remove_frontmatter)
                          options[:remove_frontmatter]
                        elsif !self['remove_frontmatter'].nil?
                          self['remove_frontmatter']
                        else
                          true
                        end,
    verbose: options.key?(:verbose) ? options[:verbose] : (self['verbose'] || false),
    # Bulk transformation options
    suffix: options[:suffix] || self['suffix'] || '.llm',
    excludes: options[:excludes] || self['excludes'] || [],
    bulk: options.key?(:bulk) ? options[:bulk] : (self['bulk'] || false),
    include_hidden: options.key?(:include_hidden) ? options[:include_hidden] : (self['include_hidden'] || false),
    # New compression options
    remove_code_examples: if options.key?(:remove_code_examples)
                            options[:remove_code_examples]
                          else
                            self['remove_code_examples'] || false
                          end,
    remove_images: if options.key?(:remove_images)
                     options[:remove_images]
                   else
                     self['remove_images'] || false
                   end,
    simplify_links: if options.key?(:simplify_links)
                      options[:simplify_links]
                    else
                      self['simplify_links'] || false
                    end,
    remove_blockquotes: if options.key?(:remove_blockquotes)
                          options[:remove_blockquotes]
                        else
                          self['remove_blockquotes'] || false
                        end,
    generate_toc: if options.key?(:generate_toc)
                    options[:generate_toc]
                  else
                    self['generate_toc'] || false
                  end,
    custom_instruction: options[:custom_instruction] || self['custom_instruction'],
    remove_stopwords: if options.key?(:remove_stopwords)
                        options[:remove_stopwords]
                      else
                        self['remove_stopwords'] || false
                      end,
    remove_duplicates: if options.key?(:remove_duplicates)
                         options[:remove_duplicates]
                       else
                         self['remove_duplicates'] || false
                       end,
    # New RAG enhancement options
    normalize_headings: if options.key?(:normalize_headings)
                          options[:normalize_headings]
                        else
                          self['normalize_headings'] || false
                        end,
    heading_separator: options[:heading_separator] || self['heading_separator'] || ' / ',
    include_metadata: if options.key?(:include_metadata)
                        options[:include_metadata]
                      else
                        self['include_metadata'] || false
                      end,
    include_tokens: if options.key?(:include_tokens)
                      options[:include_tokens]
                    else
                      self['include_tokens'] || false
                    end,
    include_timestamps: if options.key?(:include_timestamps)
                          options[:include_timestamps]
                        else
                          self['include_timestamps'] || false
                        end,
    include_priority: if options.key?(:include_priority)
                        options[:include_priority]
                      else
                        self['include_priority'] || false
                      end,
    calculate_compression: if options.key?(:calculate_compression)
                             options[:calculate_compression]
                           else
                             self['calculate_compression'] || false
                           end
  }.tap do |merged|
    merged[:content] = options[:content] if options.key?(:content)
    merged[:source_url] = options[:source_url] if options.key?(:source_url)
  end
end