Class: Vedeu::Editor::Editor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common
Defined in:
lib/vedeu/editor/editor.rb

Overview

Handles keypresses for a named document whilst the terminal is in fake mode.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, name:) ⇒ Vedeu::Editor::Editor

Returns a new instance of Vedeu::Editor::Editor.

Parameters:

  • name (String|Symbol)
  • input (String|Symbol)


40
41
42
43
# File 'lib/vedeu/editor/editor.rb', line 40

def initialize(input:, name:)
  @input = input
  @name  = name
end

Instance Attribute Details

#inputSymbol|String (readonly, protected)

Returns:

  • (Symbol|String)


71
72
73
# File 'lib/vedeu/editor/editor.rb', line 71

def input
  @input
end

#nameString (readonly, protected)

Returns:

  • (String)


75
76
77
# File 'lib/vedeu/editor/editor.rb', line 75

def name
  @name
end

Class Method Details

.keypress(input:, name:) ⇒ String|Symbol

Send given input to the named document.

Parameters:

  • name (String|Symbol)
  • input (String|Symbol)

Returns:

  • (String|Symbol)


31
32
33
# File 'lib/vedeu/editor/editor.rb', line 31

def self.keypress(input:, name:)
  new(input: input, name: name).keypress
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#demodulize(klass) ⇒ String Originally defined in module Common

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#documentVedeu::Editor::Document (private)

Return the document by name from the documents repository.



82
83
84
# File 'lib/vedeu/editor/editor.rb', line 82

def document
  @document ||= Vedeu.documents.by_name(name)
end

#keypressString|Symbol

Send given input to the named document.

Returns:

  • (String|Symbol)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vedeu/editor/editor.rb', line 48

def keypress
  return input unless document

  case input
  when :backspace then delete_character
  when :delete    then delete_line
  when :ctrl_c    then Vedeu.trigger(:_exit_)
  when :down      then down
  when :enter     then insert_line
  when :escape    then Vedeu.trigger(:_mode_switch_)
  when :left      then left
  when :right     then right
  when :tab       then execute
  when :up        then up
  else
    insert_character(input)
  end
end

#present?(variable) ⇒ Boolean Originally defined in module Common

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#snake_case(name) ⇒ String Originally defined in module Common

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)