Class: Yaml::Converter::StreamingEmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml/converter/streaming_emitter.rb

Overview

StreamingEmitter converts YAML to Markdown incrementally.
It mirrors MarkdownEmitter + StateMachine behavior while writing to an IO target.
Intended for very large inputs to avoid building all output in memory.

Constant Summary collapse

START_YAML =
"```yaml"
END_YAML =
"```"

Instance Method Summary collapse

Constructor Details

#initialize(options, io) ⇒ StreamingEmitter

Returns a new instance of StreamingEmitter.

Parameters:

  • options (Hash)

    same normalized options as Config.resolve

  • io (#<<)

    destination IO (e.g., File) that receives lines with ā€œ\nā€



17
18
19
20
21
22
23
# File 'lib/yaml/converter/streaming_emitter.rb', line 17

def initialize(options, io)
  @options = options
  @io = io
  @validation_status = :ok
  @state = :text
  @_last_line_blank = nil
end

Instance Method Details

#emit_file(input_path) ⇒ void

This method returns an undefined value.

Stream-convert an input file path to the configured IO.

Parameters:

  • input_path (String)


35
36
37
38
39
40
41
42
43
# File 'lib/yaml/converter/streaming_emitter.rb', line 35

def emit_file(input_path)
  File.open(input_path, "r") do |f|
    f.each_line do |raw|
      emit_line(raw)
    end
  end
  close_yaml
  emit_footer if @options[:emit_footer]
end

#set_validation_status(status) ⇒ void

This method returns an undefined value.

Set the validation status used when injecting the validation status line.

Parameters:

  • status (Symbol)

    :ok or :fail



28
29
30
# File 'lib/yaml/converter/streaming_emitter.rb', line 28

def set_validation_status(status)
  @validation_status = status
end