Class: Kohagi::SummaryLine

Inherits:
Object
  • Object
show all
Defined in:
lib/kohagi/summary_line.rb

Overview

kohagi's one-line run summary from stderr, parsed into a value object:

kohagi: model=cl-nagoya/ruri-v3-130m dim=512 in=2141 out=2141 skipped=0 truncated=3

SummaryLine.parse returns an instance, or nil when stderr carries no such line, so the caller can fall back to values it computed from the stream. A field the line omits (an older kohagi has no truncated) reads as nil. Knowing kohagi's stderr text format lives here, not in the Summary data.

Constant Summary collapse

MARKER =
"kohagi: model="
MODEL =
/\bmodel=(?<value>\S+)/
NUMERIC =
%i[dim out skipped truncated].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ SummaryLine

Returns a new instance of SummaryLine.



25
26
27
28
29
30
31
# File 'lib/kohagi/summary_line.rb', line 25

def initialize(line)
  @model = capture(line, MODEL)
  NUMERIC.each do |name|
    value = capture(line, /\b#{name}=(?<value>\d+)\b/)
    instance_variable_set("@#{name}", value&.to_i)
  end
end

Instance Attribute Details

#dimObject (readonly)

Returns the value of attribute dim.



17
18
19
# File 'lib/kohagi/summary_line.rb', line 17

def dim
  @dim
end

#modelObject (readonly)

Returns the value of attribute model.



17
18
19
# File 'lib/kohagi/summary_line.rb', line 17

def model
  @model
end

#outObject (readonly)

Returns the value of attribute out.



17
18
19
# File 'lib/kohagi/summary_line.rb', line 17

def out
  @out
end

#skippedObject (readonly)

Returns the value of attribute skipped.



17
18
19
# File 'lib/kohagi/summary_line.rb', line 17

def skipped
  @skipped
end

#truncatedObject (readonly)

Returns the value of attribute truncated.



17
18
19
# File 'lib/kohagi/summary_line.rb', line 17

def truncated
  @truncated
end

Class Method Details

.parse(stderr) ⇒ Object

The parsed summary line in stderr, or nil if there isn't one.



20
21
22
23
# File 'lib/kohagi/summary_line.rb', line 20

def self.parse(stderr)
  line = stderr.to_s.lines.reverse.find { |l| l.include?(MARKER) }
  line && new(line)
end