Module: Vedeu::Input::Store

Extended by:
Store
Included in:
Store
Defined in:
lib/vedeu/input/store.rb

Overview

Stores each keypress or command to be retrieved later.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_command(command) ⇒ Hash<Symbol => Array<Symbol|String>>

Add a command (a collection of characters/keypresses from an Editor::Document) to the store. Used by Vedeu internally to store commands entered.

Examples:

Vedeu.add_command(:some_command)

Parameters:

  • command (Symbol|String)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


20
21
22
# File 'lib/vedeu/input/store.rb', line 20

def add_command(command)
  all_commands << command
end

.add_keypress(keypress) ⇒ Hash<Symbol => Array<Symbol|String>>

Add a keypress to the store. Used by Vedeu internally to store a keypress entered.

Examples:

Vedeu.add_keypress(:escape)

Parameters:

  • keypress (Symbol|String)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


32
33
34
# File 'lib/vedeu/input/store.rb', line 32

def add_keypress(keypress)
  all_keypresses << keypress
end

.allHash<Symbol => Array<Symbol|String>>

Access all commands and keypresses stored.

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


39
40
41
# File 'lib/vedeu/input/store.rb', line 39

def all
  storage
end

.all_commandsArray<Symbol|String>

Access all commands stored.

Examples:

Vedeu.all_commands

Returns:

  • (Array<Symbol|String>)


49
50
51
# File 'lib/vedeu/input/store.rb', line 49

def all_commands
  storage[:commands]
end

.all_keypressesArray<Symbol|String>

Access all keypresses stored.

Examples:

Vedeu.all_keypresses

Returns:

  • (Array<Symbol|String>)


59
60
61
# File 'lib/vedeu/input/store.rb', line 59

def all_keypresses
  storage[:keypresses]
end

.in_memoryHash<Symbol => Array<Symbol|String>> (private)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


103
104
105
106
107
108
# File 'lib/vedeu/input/store.rb', line 103

def in_memory
  {
    commands:   [],
    keypresses: [],
  }
end

.last_commandNilClass|Symbol|String

Access the last command stored. If no commands have been entered since the client application started, then this will return nil.

Examples:

Vedeu.last_command

Returns:

  • (NilClass|Symbol|String)


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

def last_command
  all_commands[-1]
end

.last_keypressNilClass|Symbol|String

Access the last keypress stored. If no keys have been pressed since the client application started, then this will return nil.

Examples:

Vedeu.last_keypress

Returns:

  • (NilClass|Symbol|String)


83
84
85
# File 'lib/vedeu/input/store.rb', line 83

def last_keypress
  all_keypresses[-1]
end

.resetHash<Symbol => Array<Symbol|String>>

Remove all stored entries. Any commands or keypresses entered before calling this method will be removed.

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


91
92
93
# File 'lib/vedeu/input/store.rb', line 91

def reset
  @storage = in_memory
end

.storageHash<Symbol => Array<Symbol|String>> (private)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


98
99
100
# File 'lib/vedeu/input/store.rb', line 98

def storage
  @storage ||= in_memory
end

Instance Method Details

#add_command(command) ⇒ Hash<Symbol => Array<Symbol|String>>

Add a command (a collection of characters/keypresses from an Editor::Document) to the store. Used by Vedeu internally to store commands entered.

Examples:

Vedeu.add_command(:some_command)

Parameters:

  • command (Symbol|String)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


20
21
22
# File 'lib/vedeu/input/store.rb', line 20

def add_command(command)
  all_commands << command
end

#add_keypress(keypress) ⇒ Hash<Symbol => Array<Symbol|String>>

Add a keypress to the store. Used by Vedeu internally to store a keypress entered.

Examples:

Vedeu.add_keypress(:escape)

Parameters:

  • keypress (Symbol|String)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


32
33
34
# File 'lib/vedeu/input/store.rb', line 32

def add_keypress(keypress)
  all_keypresses << keypress
end

#allHash<Symbol => Array<Symbol|String>>

Access all commands and keypresses stored.

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


39
40
41
# File 'lib/vedeu/input/store.rb', line 39

def all
  storage
end

#all_commandsArray<Symbol|String>

Access all commands stored.

Examples:

Vedeu.all_commands

Returns:

  • (Array<Symbol|String>)


49
50
51
# File 'lib/vedeu/input/store.rb', line 49

def all_commands
  storage[:commands]
end

#all_keypressesArray<Symbol|String>

Access all keypresses stored.

Examples:

Vedeu.all_keypresses

Returns:

  • (Array<Symbol|String>)


59
60
61
# File 'lib/vedeu/input/store.rb', line 59

def all_keypresses
  storage[:keypresses]
end

#in_memoryHash<Symbol => Array<Symbol|String>> (private)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


103
104
105
106
107
108
# File 'lib/vedeu/input/store.rb', line 103

def in_memory
  {
    commands:   [],
    keypresses: [],
  }
end

#last_commandNilClass|Symbol|String

Access the last command stored. If no commands have been entered since the client application started, then this will return nil.

Examples:

Vedeu.last_command

Returns:

  • (NilClass|Symbol|String)


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

def last_command
  all_commands[-1]
end

#last_keypressNilClass|Symbol|String

Access the last keypress stored. If no keys have been pressed since the client application started, then this will return nil.

Examples:

Vedeu.last_keypress

Returns:

  • (NilClass|Symbol|String)


83
84
85
# File 'lib/vedeu/input/store.rb', line 83

def last_keypress
  all_keypresses[-1]
end

#resetHash<Symbol => Array<Symbol|String>>

Remove all stored entries. Any commands or keypresses entered before calling this method will be removed.

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


91
92
93
# File 'lib/vedeu/input/store.rb', line 91

def reset
  @storage = in_memory
end

#storageHash<Symbol => Array<Symbol|String>> (private)

Returns:

  • (Hash<Symbol => Array<Symbol|String>>)


98
99
100
# File 'lib/vedeu/input/store.rb', line 98

def storage
  @storage ||= in_memory
end