Vibescript Showcase
Text toolkit
Slice and align text with Ruby-style partition, center, chars, and start_with? helpers.
Source
showcase/strings/text_toolkit.vibe
# title: Text toolkit
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Slice and align text with Ruby-style partition, center, chars, and start_with? helpers.
# description: The 1.0 string library fills out the Ruby-compatible surface, so parsing and formatting stay declarative instead of hand-rolled index math.
# tags: strings, text, formatting
# vibe: 0.4
def split_setting(line: string) -> hash
parts = line.partition("=")
{
key: parts[0],
assigned: parts[1] == "=",
value: parts[2]
}
end
def domain_of(email: string) -> string
email.rpartition("@")[2]
end
def banner(label: string, width: int) -> string
label.center(width, "*")
end
def initials(name: string) -> string
name.split(" ").map { |word| word.chars[0] }.join("")
end
def flagged?(line: string) -> bool
line.start_with?("WARN", "ERROR")
end
def run
{
setting: split_setting("timeout=30"),
no_assignment: split_setting("bare-token"),
domain: domain_of("ada@vibescript.dev"),
banner: banner(" ship it ", 20),
initials: initials("Grace Brewster Hopper"),
warn_flagged: flagged?("WARN disk almost full"),
info_flagged: flagged?("INFO all good")
}
end
Output
Press run to execute run from this example.