struct WordMage::SyllableCountSpec

Overview

Specifies how many syllables a word should have.

Supports three modes:

Example

exact = SyllableCountSpec.exact(3)                    # Always 3 syllables
range = SyllableCountSpec.range(2, 4)                 # 2-4 syllables
weighted = SyllableCountSpec.weighted({2 => 1.0, 3 => 3.0, 4 => 1.0})  # Prefer 3

Defined in:

word_spec.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(type : Type, min : Int32, max : Int32, weights : Hash(Int32, Float32) | Nil = nil) #

[View source]

Class Method Detail

def self.exact(count : Int32) #

Creates a spec for exactly N syllables.


[View source]
def self.range(min : Int32, max : Int32) #

Creates a spec for a range of syllables with uniform distribution.


[View source]
def self.weighted(weights : Hash(Int32, Float32)) #

Creates a spec for weighted syllable distribution.

Parameters

  • #weights: Hash mapping syllable counts to their relative weights

[View source]

Instance Method Detail

def generate_count : Int32 #

Generates a syllable count according to this spec.

Returns

Number of syllables for the word


[View source]
def max : Int32 #

[View source]
def min : Int32 #

[View source]
def type : Type #

[View source]
def weights : Hash(Int32, Float32) | Nil #

[View source]