Class: Vedeu::Editor::Document Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Document
- Extended by:
- Forwardable
- Includes:
- Repositories::Defaults, Repositories::Model
- Defined in:
- lib/vedeu/editor/document.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.
A collection of keypresses ordered by input.
Instance Attribute Summary collapse
- #attributes ⇒ Hash<Symbol => String|Symbol| Vedeu::Repositories::Repository> readonly private
- #data ⇒ String
- #name ⇒ String|Symbol
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
Class Method Summary collapse
-
.store(attributes = {}) ⇒ Object
private
Store an instance of this class with its repository.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#cursor ⇒ Vedeu::Editor::Cursor
private
private
Return a virtual cursor to track the cursor position within the document.
-
#defaults ⇒ Hash<Symbol => void|Symbol]
private
private
Returns the default options/attributes for this class.
-
#delete_character ⇒ Vedeu::Editor::Document
private
Deletes the character from the line where the cursor is currently positioned.
-
#delete_line ⇒ Vedeu::Editor::Document
private
Delete a line.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
- #document_start? ⇒ Boolean private private
-
#down ⇒ Vedeu::Editor::Document
private
Move the virtual cursor down.
-
#execute ⇒ String
private
Returns the document as a string with line breaks if there is more than one line.
- #first_char? ⇒ Boolean private private
- #first_line? ⇒ Boolean private private
-
#initialize(attributes = {}) ⇒ void
included
from Repositories::Defaults
private
Returns a new instance of the class including this module.
-
#insert_character(character) ⇒ Vedeu::Editor::Document
private
Inserts the given character in to the line where the cursor is currently positioned.
-
#insert_line ⇒ Vedeu::Editor::Document
private
Insert an empty line.
- #last_char? ⇒ Boolean private private
- #last_line? ⇒ Boolean private private
-
#left ⇒ Vedeu::Editor::Document
private
Move the virtual cursor left.
-
#line(index = y) ⇒ Array<String|void>
private
Returns the current line from the collection of lines.
-
#lines ⇒ Array<String|void>
private
Returns the collection of lines which constitutes the document content.
- #next_line_size ⇒ Fixnum private private
-
#output ⇒ Array<Vedeu::Views::Char>
private
private
Return the data needed to render the document, based on the current virtual cursor position.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
- #prev_line_size ⇒ Fixnum private private
-
#refresh ⇒ Vedeu::Editor::Document
private
Store the document in the documents repository, clear and send the content to the terminal.
-
#reset! ⇒ Vedeu::Editor::Document
private
Reset the document to the empty state.
-
#right ⇒ Vedeu::Editor::Document
private
Move the virtual cursor right.
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#up ⇒ Vedeu::Editor::Document
private
Move the virtual cursor up.
Instance Attribute Details
#attributes ⇒ Hash<Symbol => String|Symbol| Vedeu::Repositories::Repository> (readonly)
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.
24 25 26 |
# File 'lib/vedeu/editor/document.rb', line 24 def attributes @attributes end |
#data ⇒ String
28 29 30 |
# File 'lib/vedeu/editor/document.rb', line 28 def data @data end |
#name ⇒ String|Symbol
32 33 34 |
# File 'lib/vedeu/editor/document.rb', line 32 def name @name end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
Class Method Details
.store(attributes = {}) ⇒ Object
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.
Store an instance of this class with its repository.
38 39 40 |
# File 'lib/vedeu/editor/document.rb', line 38 def self.store(attributes = {}) new(attributes).store 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.
#cursor ⇒ Vedeu::Editor::Cursor (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.
Return a virtual cursor to track the cursor position within the document.
221 222 223 |
# File 'lib/vedeu/editor/document.rb', line 221 def cursor @cursor ||= Vedeu::Editor::Cursor.new(name: name) end |
#defaults ⇒ Hash<Symbol => void|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 the default options/attributes for this class.
228 229 230 231 232 233 234 |
# File 'lib/vedeu/editor/document.rb', line 228 def defaults { data: Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new]), name: nil, repository: Vedeu.documents, } end |
#delete_character ⇒ Vedeu::Editor::Document
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.
Deletes the character from the line where the cursor is currently positioned.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vedeu/editor/document.rb', line 62 def delete_character return self if document_start? if first_char? && y > 0 delete_line return else @lines = lines.delete_character(y, x - 1) left end refresh end |
#delete_line ⇒ Vedeu::Editor::Document
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.
Delete a line.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vedeu/editor/document.rb', line 83 def delete_line @lines = lines.delete_line(y) up cursor.x = line.size cursor.refresh refresh end |
#demodulize(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.
Removes the module part from the expression in the string.
#document_start? ⇒ 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.
213 214 215 |
# File 'lib/vedeu/editor/document.rb', line 213 def document_start? first_char? && first_line? end |
#down ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor down.
202 203 204 205 206 207 208 |
# File 'lib/vedeu/editor/document.rb', line 202 def down return self if last_line? cursor.down(next_line_size).refresh self end |
#execute ⇒ 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.
Returns the document as a string with line breaks if there is more than one line.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vedeu/editor/document.rb', line 46 def execute command = lines.map(&:to_s).join("\n".freeze) reset! Vedeu.trigger(:_clear_view_content_, name) Vedeu.trigger(:_command_, command) command end |
#first_char? ⇒ 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.
237 238 239 |
# File 'lib/vedeu/editor/document.rb', line 237 def first_char? x - 1 < 0 end |
#first_line? ⇒ 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.
242 243 244 |
# File 'lib/vedeu/editor/document.rb', line 242 def first_line? y - 1 < 0 end |
#initialize(attributes = {}) ⇒ void Originally defined in module Repositories::Defaults
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.
If a particular key is missing from the attributes parameter, then it is added with the respective value from #defaults.
Returns a new instance of the class including this module.
#insert_character(character) ⇒ Vedeu::Editor::Document
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.
Inserts the given character in to the line where the cursor is currently positioned.
100 101 102 103 104 105 106 107 108 |
# File 'lib/vedeu/editor/document.rb', line 100 def insert_character(character) return self if character.is_a?(Symbol) @lines = lines.insert_character(character, y, x) right refresh end |
#insert_line ⇒ Vedeu::Editor::Document
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.
Insert an empty line.
113 114 115 116 117 118 119 |
# File 'lib/vedeu/editor/document.rb', line 113 def insert_line @lines = lines.insert_line(y + 1) down refresh end |
#last_char? ⇒ 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.
247 248 249 |
# File 'lib/vedeu/editor/document.rb', line 247 def last_char? x + 1 > line.size end |
#last_line? ⇒ 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.
252 253 254 |
# File 'lib/vedeu/editor/document.rb', line 252 def last_line? y + 1 >= lines.size end |
#left ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor left.
169 170 171 172 173 174 175 |
# File 'lib/vedeu/editor/document.rb', line 169 def left return self if first_char? cursor.left.refresh self end |
#line(index = y) ⇒ Array<String|void>
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 the current line from the collection of lines.
125 126 127 |
# File 'lib/vedeu/editor/document.rb', line 125 def line(index = y) lines.line(index) end |
#lines ⇒ Array<String|void>
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 the collection of lines which constitutes the document content.
133 134 135 |
# File 'lib/vedeu/editor/document.rb', line 133 def lines @lines ||= Vedeu::Editor::Lines.coerce(data) end |
#next_line_size ⇒ Fixnum (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.
257 258 259 |
# File 'lib/vedeu/editor/document.rb', line 257 def next_line_size line(y + 1).size end |
#output ⇒ Array<Vedeu::Views::Char> (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.
Return the data needed to render the document, based on the current virtual cursor position. This output may be a cropped representation of the full document depending on the size of the interface.
267 268 269 270 271 272 |
# File 'lib/vedeu/editor/document.rb', line 267 def output Vedeu::Editor::Cropper.new(lines: lines, name: name, ox: ox, oy: oy). 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.
#prev_line_size ⇒ Fixnum (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.
275 276 277 |
# File 'lib/vedeu/editor/document.rb', line 275 def prev_line_size line(y - 1).size end |
#refresh ⇒ Vedeu::Editor::Document
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.
Store the document in the documents repository, clear and send the content to the terminal.
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/vedeu/editor/document.rb', line 154 def refresh store Vedeu.trigger(:_clear_view_content_, name) Vedeu.buffer_update(output) Vedeu.direct_write(output.map(&:to_s).join) self end |
#reset! ⇒ Vedeu::Editor::Document
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.
Reset the document to the empty state.
140 141 142 143 144 145 146 147 148 |
# File 'lib/vedeu/editor/document.rb', line 140 def reset! @cursor = cursor.reset! @lines = defaults[:data] cursor.refresh refresh end |
#right ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor right.
180 181 182 183 184 185 186 |
# File 'lib/vedeu/editor/document.rb', line 180 def right return self if last_char? cursor.right.refresh self end |
#snake_case(name) ⇒ 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.
#store ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#up ⇒ Vedeu::Editor::Document
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.
Move the virtual cursor up.
191 192 193 194 195 196 197 |
# File 'lib/vedeu/editor/document.rb', line 191 def up return self if first_line? cursor.up(prev_line_size).refresh self end |