Class: Vedeu::Input::Read Private
- Inherits:
-
Object
- Object
- Vedeu::Input::Read
- 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.
Class Method Summary collapse
Instance Method Summary collapse
- #console ⇒ IO private private
- #cooked? ⇒ Boolean private private
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
- #fake? ⇒ Boolean private private
-
#initialize(input = nil, options = {}) ⇒ Vedeu::Input::Read
constructor
private
Returns a new instance of Vedeu::Input::Read.
- #input ⇒ String private private
- #input? ⇒ Boolean private private
- #mode ⇒ Symbol private private
- #modes ⇒ Array<Symbol> private private
- #options ⇒ Hash<Symbol => Symbol> private private
- #raw? ⇒ Boolean private private
- #read ⇒ String private
- #valid_mode? ⇒ Boolean private private
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
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.
30 31 32 33 |
# File 'lib/vedeu/input/read.rb', line 30 def initialize(input = nil, = {}) @input = input @options = end |
Class Method Details
.read(input = nil, options = {}) ⇒ Object
20 21 22 |
# File 'lib/vedeu/input/read.rb', line 20 def self.read(input = nil, = {}) new(input, ).read end |
Instance Method Details
#console ⇒ IO (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.
54 55 56 |
# File 'lib/vedeu/input/read.rb', line 54 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.
59 60 61 |
# File 'lib/vedeu/input/read.rb', line 59 def cooked? mode == :cooked end |
#defaults ⇒ Hash<Symbol => void> (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.
The default options/attributes for a new instance of this class.
64 65 66 67 68 |
# File 'lib/vedeu/input/read.rb', line 64 def defaults { mode: :cooked, } end |
#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.
71 72 73 |
# File 'lib/vedeu/input/read.rb', line 71 def fake? mode == :fake end |
#input ⇒ String (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.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/input/read.rb', line 76 def input @_input ||= if input? @input elsif cooked? console.gets.chomp elsif raw? Vedeu::Input::Translator.translate(Vedeu::Input::Raw.read) elsif fake? console.cooked do Vedeu::Terminal.debugging! console.gets.chomp end end end |
#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.
97 98 99 |
# File 'lib/vedeu/input/read.rb', line 97 def input? present?(@input) end |
#mode ⇒ 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.
103 104 105 106 107 108 109 110 |
# File 'lib/vedeu/input/read.rb', line 103 def mode unless valid_mode? raise Vedeu::Error::InvalidSyntax, ':mode must be `:raw`, `:fake` or `:cooked`.' end [:mode] end |
#modes ⇒ Array<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.
113 114 115 116 117 118 119 |
# File 'lib/vedeu/input/read.rb', line 113 def modes [ :cooked, :fake, :raw, ] end |
#options ⇒ Hash<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.
122 123 124 |
# File 'lib/vedeu/input/read.rb', line 122 def defaults.merge!(@options) end |
#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.
127 128 129 |
# File 'lib/vedeu/input/read.rb', line 127 def raw? mode == :raw end |
#read ⇒ String
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.
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 |
#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.
132 133 134 |
# File 'lib/vedeu/input/read.rb', line 132 def valid_mode? modes.include?([:mode]) end |