Class: Dsu::Views::EntryGroup::Edit

Inherits:
Object
  • Object
show all
Defined in:
lib/dsu/views/entry_group/edit.rb

Overview

TODO: I18n this class.

Instance Method Summary collapse

Constructor Details

#initialize(entry_group:, options: {}) ⇒ Edit

Returns a new instance of Edit.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/dsu/views/entry_group/edit.rb', line 11

def initialize(entry_group:, options: {})
  raise ArgumentError, 'entry_group is nil' if entry_group.nil?
  raise ArgumentError, 'entry_group is the wrong object type' unless entry_group.is_a?(Models::EntryGroup)
  raise ArgumentError, 'options is nil' if options.nil?
  raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)

  @entry_group = entry_group
  @options = options || {}
end

Instance Method Details

#renderObject



21
22
23
# File 'lib/dsu/views/entry_group/edit.rb', line 21

def render
  puts render_as_string
end

#render_as_stringObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dsu/views/entry_group/edit.rb', line 25

def render_as_string
  # Just in case the entry group is invalid, we'll validate it before displaying it.
  entry_group.validate!

  <<~EDIT_VIEW
    #{banner_line}
    # Editing DSU Entries for #{entry_group.time_formatted}
    #{banner_line}

    #{entry_group_view&.chomp}

    #{banner_line}
    # INSTRUCTIONS
    #{banner_line}
    #    ADD a DSU entry: type an ENTRY DESCRIPTION on a new line.
    #   EDIT a DSU entry: change the existing ENTRY DESCRIPTION.
    # DELETE a DSU entry: delete the ENTRY DESCRIPTION.
    #  NOTE: deleting all of the ENTRY DESCRIPTIONs will delete the entry group file;
    #        this is preferable if this is what you want to do :)
    # REORDER a DSU entry: reorder the ENTRY DESCRIPTIONs in order preference.
    #
    # *** When you are done, save and close your editor ***
    #{banner_line}
  EDIT_VIEW
end