Class: Appear::Tmux::TmuxValue

Inherits:
Util::ValueClass show all
Defined in:
lib/appear/tmux.rb

Overview

Base value class for Tmux values. This class works in concert with the Tmux service to make a fluent Tmux API easy.

TmuxValues all have a reference to the Tmux service that created them, so that they can implement methods that proxy Tmux service interaction.

Direct Known Subclasses

Client, Pane, Session, Window

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Util::ValueClass

#initialize, properties

Constructor Details

This class inherits a constructor from Appear::Util::ValueClass

Class Method Details

.format_stringString

The format string we pass to Tmux when we expect a result of this class’s type. This format string should cause Tmux to return a value we can hand to selfself.parse

Returns:

  • (String)


39
40
41
42
43
44
45
46
47
# File 'lib/appear/tmux.rb', line 39

def self.format_string
  result = ""
  @tmux_attrs.each do |var, opts|
    next unless opts[:tmux]
    part = ' ' + var.to_s + ':#{' + opts[:tmux].to_s + '}'
    result += part
  end
  result
end

.parse(tmux_hash, tmux) ⇒ Object

Parse a raw data has as returned by the Appear::Tmux service into an instance of this class.

Parameters:

  • tmux_hash (Hash)
  • tmux (Tmux)

    the tmux service



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/appear/tmux.rb', line 54

def self.parse(tmux_hash, tmux)
  result = { :tmux => tmux }
  tmux_hash.each do |var, tmux_val|
    parser = @tmux_attrs[var][:parse]
    if parser
      result[var] = parser.to_proc.call(tmux_val)
    else
      result[var] = tmux_val
    end
  end
  self.new(result)
end

.property(name, opts = {}) ⇒ Object

returns the type-coerced version of this field. A symbol can be used, just like with usual block syntax.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :tmux (Symbol)

    tmux format string name of this attribute

  • :parse (#to_proc)

    proc taking a String (read from tmux) and



28
29
30
31
32
# File 'lib/appear/tmux.rb', line 28

def self.property(name, opts = {})
  var = super(name, opts)
  @tmux_attrs ||= {}
  @tmux_attrs[var] = opts if opts[:tmux]
end

Instance Method Details

#tmuxTmux

Returns the tmux service that created this pane.

Returns:

  • (Tmux)

    the tmux service that created this pane



22
# File 'lib/appear/tmux.rb', line 22

property :tmux