Class: Vedeu::Input::Read Private

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vedeu/input/read.rb

Overview

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

Directly read from the terminal.

Examples:

Vedeu.read(input, options)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = nil, options = {}) ⇒ Vedeu::Input::Read

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.

Returns a new instance of Vedeu::Input::Read.

Parameters:

  • input (NilClass|String) (defaults to: nil)
  • options (Hash<Symbol => Symbol]) (defaults to: {})

    ptions [Hash<Symbol => Symbol]

  • mode (Hash)

    a customizable set of options



30
31
32
33
# File 'lib/vedeu/input/read.rb', line 30

def initialize(input = nil, options = {})
  @input   = input
  @options = options
end

Instance Attribute Details

#inputString (readonly, private)

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.

Returns:

  • (String)


55
56
57
# File 'lib/vedeu/input/read.rb', line 55

def input
  @input
end

Class Method Details

.read(input = nil, options = {}) ⇒ Object

See Also:



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

def self.read(input = nil, options = {})
  new(input, options).read
end

Instance Method Details

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

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.

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

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#become(klass, attributes) ⇒ Class Originally defined in module Common

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.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#consoleIO (private)

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.

Returns:

  • (IO)


60
61
62
# File 'lib/vedeu/input/read.rb', line 60

def console
  @console ||= Vedeu::Terminal.console
end

#cooked?Boolean (private)

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.

Returns:



65
66
67
# File 'lib/vedeu/input/read.rb', line 65

def cooked?
  mode == :cooked
end

#defaultsHash<Symbol => Symbol> (private)

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.

Returns:

  • (Hash<Symbol => Symbol>)


70
71
72
73
74
# File 'lib/vedeu/input/read.rb', line 70

def defaults
  {
    mode: :cooked,
  }
end

#escape?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#fake?Boolean (private)

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.

Returns:



77
78
79
# File 'lib/vedeu/input/read.rb', line 77

def fake?
  mode == :fake
end

#falsy?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#hash?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

#input?Boolean (private)

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.

Returns:



113
114
115
# File 'lib/vedeu/input/read.rb', line 113

def input?
  present?(@input)
end

#line_model?Boolean Originally defined in module Common

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.

Returns a boolean indicating the model is a Views::Line.

Returns:

#modeSymbol (private)

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.

Returns:

  • (Symbol)

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



119
120
121
122
123
124
125
126
# File 'lib/vedeu/input/read.rb', line 119

def mode
  unless valid_mode?
    fail Vedeu::Error::InvalidSyntax,
         ':mode must be `:raw`, `:fake` or `:cooked`.'
  end

  options[:mode]
end

#modesArray<Symbol> (private)

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.

Returns:

  • (Array<Symbol>)


129
130
131
132
133
134
135
# File 'lib/vedeu/input/read.rb', line 129

def modes
  [
    :cooked,
    :fake,
    :raw,
  ]
end

#mouse_offString (private)

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.

Returns:

  • (String)


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

def mouse_off
  Vedeu.esc.mouse_x10_off
end

#numeric?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#optionsHash<Symbol => Symbol> (private)

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.

Returns:

  • (Hash<Symbol => Symbol>)


138
139
140
# File 'lib/vedeu/input/read.rb', line 138

def options
  defaults.merge!(@options)
end

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

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.

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

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#raw?Boolean (private)

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.

Returns:



143
144
145
# File 'lib/vedeu/input/read.rb', line 143

def raw?
  mode == :raw
end

#readString

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.

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vedeu/input/read.rb', line 36

def read
  if cooked?
    Vedeu.trigger(:_command_, input)

  elsif raw?
    Vedeu.trigger(:_keypress_, input)

  elsif fake?
    input

  end

  input
end

#show_cursorString (private)

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.

Returns:

  • (String)


87
88
89
# File 'lib/vedeu/input/read.rb', line 87

def show_cursor
  Vedeu.esc.show_cursor
end

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

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.

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"

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

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?Boolean Originally defined in module Common

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.

Returns a boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#truthy?(value) ⇒ Boolean Originally defined in module Common

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.

Returns a boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#valid_mode?Boolean (private)

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.

Returns:



148
149
150
# File 'lib/vedeu/input/read.rb', line 148

def valid_mode?
  modes.include?(options[:mode])
end

#view_model?Boolean Originally defined in module Common

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.

Returns a boolean indicating the model is a Views::View.

Returns: