Module: Roast::Cog::Output::WithNumber

Included in:
Roast::Cogs::Agent::Output, Roast::Cogs::Chat::Output, Roast::Cogs::Cmd::Output
Defined in:
lib/roast/cog/output.rb

Overview

@requires_ancestor: Roast::Cog::Output

Instance Method Summary collapse

Instance Method Details

#floatObject

Get parsed float from the output, returning nil if parsing fails

This method attempts to parse a float from the output text using multiple permissive fallback strategies to extract a substring that looks like a number.

Returns ‘nil` if output text does not contain any value that can be parsed as a number.

#### See Also

  • ‘float!`

  • ‘integer!`

  • ‘integer`

: () -> Float?



165
166
167
168
169
# File 'lib/roast/cog/output.rb', line 165

def float
  float!
rescue ArgumentError
  nil
end

#float!Object

Get parsed float from the output, raising an error if parsing fails

This method attempts to parse a float from the output text using multiple permissive fallback strategies to extract a substring that looks like a number.

Raises ‘ArgumentError` if output text does not contain any value that can be parsed as a number.

#### See Also

  • ‘float`

  • ‘integer!`

  • ‘integer`

: () -> Float



148
149
150
# File 'lib/roast/cog/output.rb', line 148

def float!
  @float ||= parse_number_with_fallbacks(raw_text || "")
end

#integerObject

Get parsed integer from the output, returning nil if parsing fails

This method attempts to parse an integer from the output text using multiple permissive fallback strategies to extract a substring that looks like a number. This method will attempt to parse and round a floating point value; it will not strictly match only integers in the source text.

Returns ‘nil` if output text does not contain any value that can be parsed as a number.

#### See Also

  • ‘integer!`

  • ‘float!`

  • ‘float`

: () -> Integer?



203
204
205
206
207
# File 'lib/roast/cog/output.rb', line 203

def integer
  integer!
rescue ArgumentError
  nil
end

#integer!Object

Get parsed integer from the output, raising an error if parsing fails

This method attempts to parse an integer from the output text using multiple permissive fallback strategies to extract a substring that looks like a number. This method will attempt to parse and round a floating point value; it will not strictly match only integers in the source text.

Raises ‘ArgumentError` if output text does not contain any value that can be parsed as a number.

#### See Also

  • ‘integer`

  • ‘float!`

  • ‘float`

: () -> Integer



185
186
187
# File 'lib/roast/cog/output.rb', line 185

def integer!
  @integer ||= float!.round
end