Class: EasyCreds::InitState
- Inherits:
-
Object
- Object
- EasyCreds::InitState
- Defined in:
- lib/easy_creds/init_state.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#dirty ⇒ Object
Returns the value of attribute dirty.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#op_values ⇒ Object
readonly
Returns the value of attribute op_values.
-
#scroll_offset ⇒ Object
Returns the value of attribute scroll_offset.
Instance Method Summary collapse
- #adjust_scroll(cursor_tree_idx, content_rows) ⇒ Object
- #clear_entry(entry) ⇒ Object
- #current ⇒ Object
-
#initialize(entries:, op_values: {}) ⇒ InitState
constructor
A new instance of InitState.
- #move_down(steps = 1) ⇒ Object
- #move_first ⇒ Object
- #move_last ⇒ Object
- #move_up(steps = 1) ⇒ Object
- #set_count ⇒ Object
- #set_entry(entry, value:, source:) ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(entries:, op_values: {}) ⇒ InitState
Returns a new instance of InitState.
31 32 33 34 35 36 37 |
# File 'lib/easy_creds/init_state.rb', line 31 def initialize(entries:, op_values: {}) @entries = entries @op_values = op_values @cursor = 0 @scroll_offset = 0 @dirty = false end |
Instance Attribute Details
#cursor ⇒ Object
Returns the value of attribute cursor.
29 30 31 |
# File 'lib/easy_creds/init_state.rb', line 29 def cursor @cursor end |
#dirty ⇒ Object
Returns the value of attribute dirty.
29 30 31 |
# File 'lib/easy_creds/init_state.rb', line 29 def dirty @dirty end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
28 29 30 |
# File 'lib/easy_creds/init_state.rb', line 28 def entries @entries end |
#op_values ⇒ Object (readonly)
Returns the value of attribute op_values.
28 29 30 |
# File 'lib/easy_creds/init_state.rb', line 28 def op_values @op_values end |
#scroll_offset ⇒ Object
Returns the value of attribute scroll_offset.
29 30 31 |
# File 'lib/easy_creds/init_state.rb', line 29 def scroll_offset @scroll_offset end |
Instance Method Details
#adjust_scroll(cursor_tree_idx, content_rows) ⇒ Object
59 60 61 62 63 |
# File 'lib/easy_creds/init_state.rb', line 59 def adjust_scroll(cursor_tree_idx, content_rows) @scroll_offset = cursor_tree_idx if cursor_tree_idx < @scroll_offset @scroll_offset = cursor_tree_idx - content_rows + 1 if cursor_tree_idx >= @scroll_offset + content_rows @scroll_offset = [@scroll_offset, 0].max end |
#clear_entry(entry) ⇒ Object
54 55 56 57 |
# File 'lib/easy_creds/init_state.rb', line 54 def clear_entry(entry) entry.value = nil entry.source = :unset end |
#current ⇒ Object
39 |
# File 'lib/easy_creds/init_state.rb', line 39 def current = entries[cursor] |
#move_down(steps = 1) ⇒ Object
44 |
# File 'lib/easy_creds/init_state.rb', line 44 def move_down(steps = 1) = @cursor = [@cursor + steps, entries.size - 1].min |
#move_first ⇒ Object
45 |
# File 'lib/easy_creds/init_state.rb', line 45 def move_first = @cursor = 0 |
#move_last ⇒ Object
46 |
# File 'lib/easy_creds/init_state.rb', line 46 def move_last = @cursor = entries.size - 1 |
#move_up(steps = 1) ⇒ Object
43 |
# File 'lib/easy_creds/init_state.rb', line 43 def move_up(steps = 1) = @cursor = [@cursor - steps, 0].max |
#set_count ⇒ Object
40 |
# File 'lib/easy_creds/init_state.rb', line 40 def set_count = entries.count(&:set?) |
#set_entry(entry, value:, source:) ⇒ Object
48 49 50 51 52 |
# File 'lib/easy_creds/init_state.rb', line 48 def set_entry(entry, value:, source:) entry.value = value entry.source = source @dirty = true end |
#total ⇒ Object
41 |
# File 'lib/easy_creds/init_state.rb', line 41 def total = entries.size |