Class: DevSystem::ShellPanel

Inherits:
Liza::Panel show all
Defined in:
lib/dev_system/sub/shell/shell_panel.rb

Defined Under Namespace

Classes: ConverterError, FormatterError

Instance Attribute Summary

Attributes inherited from Liza::Panel

#key

Instance Method Summary collapse

Methods inherited from Liza::Panel

box, #box, color, #controller, controller, division, #division, #initialize, #push, #short, #started, subsystem, #subsystem, token

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

This class inherits a constructor from Liza::Panel

Instance Method Details

#convert(format, string, options = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 87

def convert format, string, options = {}
  format = format.to_sym
  if convert? format
    log :lower, "converter found"
    converters[format][:shell].convert string, options
  else
    log :lower, "converter not found"
    string
  end
end

#convert!(format, string, options = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 76

def convert! format, string, options = {}
  format = format.to_sym
  if convert? format
    log :lower, "converter found"
    converters[format][:shell].convert string
  else
    log :lower, "converter not found"
    raise ConverterError, "no converter for #{format.inspect}"
  end
end

#convert?(format) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 71

def convert? format
  format = format.to_sym
  converters.values.any? { _1[:from] == format }
end

#converter(to, from, shell_key = from, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 49

def converter to, from, shell_key = from, options = {}
  shell = options[:shell] || Liza.const("#{shell_key}_converter_shell")

  hash = {
    to: to.to_sym,
    from: from.to_sym,
    shell: shell,
    options: options
  }
  converters[shell_key] = hash
  converters_to[to] ||= []
  converters_to[to] << hash
end

#convertersObject



63
64
65
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 63

def converters
  @converters ||= {}
end

#converters_toObject



67
68
69
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 67

def converters_to
  @converters_to ||= {}
end

#format(format, string, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 36

def format format, string, options = {}
  format = format.to_sym
  if format? format
    log :lower, "formatter found"
    formatters[format][:shell].format string, options
  else
    log :lower, "formatter not found"
    string
  end
end

#format!(format, string) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 25

def format! format, string
  format = format.to_sym
  if format? format
    log :lower, "formatter found"
    formatters[format][:shell].format string
  else
    log :lower, "formatter not found"
    raise FormatterError, "no formatter for #{format.inspect}"
  end
end

#format?(format) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 21

def format? format
  formatters.key? format.to_sym
end

#formatter(format, shell_key = format, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 7

def formatter format, shell_key = format, options = {}
  shell = options[:shell] || Liza.const("#{format}_formatter_shell")

  formatters[shell_key] = {
    format: format,
    shell: shell,
    options: options
  }
end

#formattersObject



17
18
19
# File 'lib/dev_system/sub/shell/shell_panel.rb', line 17

def formatters
  @formatters ||= {}
end