Module: Teek::UI::OptionDumpParsing Private

Defined in:
lib/teek/ui/option_dump_parsing.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Shared by every WidgetType#addressing strategy's own #option_dump (see WidgetAddressing, MenuEntryAddressing) - the raw Tcl command differs per strategy (+configure+ vs entryconfigure <index>), but both return the exact same nested-list shape, so the parsing itself lives in one place rather than two copies drifting apart.

Class Method Summary collapse

Class Method Details

.parse(app, raw) ⇒ Hash{Symbol => String}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A bare configure (or entryconfigure <index>) call returns one Tcl sublist per option: {name dbname dbclass default current} for an ordinary option, or a shorter 2-item {name aliased-name} for a synonym (e.g. -bg pointing at -background) - those carry no value of their own and are skipped.

Parameters:

  • app (Teek::App)
  • raw (String)

    the unparsed Tcl list app.command returned

Returns:

  • (Hash{Symbol => String})

    option name (no leading -) => current value



21
22
23
24
25
26
27
28
# File 'lib/teek/ui/option_dump_parsing.rb', line 21

def self.parse(app, raw)
  app.split_list(raw).each_with_object({}) do |item, dump|
    parts = app.split_list(item)
    next if parts.size < 5

    dump[parts[0].sub(/\A-/, '').to_sym] = parts[4]
  end
end