Class: CheckList::Start

Inherits:
Object
  • Object
show all
Defined in:
lib/check_list.rb

Overview

The start method for check-list

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStart

Returns a new instance of Start.



19
20
21
22
23
# File 'lib/check_list.rb', line 19

def initialize
  @opts = set_options
  @filepath = CheckList::HandleFile.new
  handler
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



17
18
19
# File 'lib/check_list.rb', line 17

def opts
  @opts
end

Instance Method Details

#handlerObject

rubocop: enable Layout/HeredocIndentation rubocop: enable Naming/HeredocDelimiterNaming



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/check_list.rb', line 46

def handler
  if @opts[:update_given]
    update
  elsif @opts[:view_given]
    view
  else
    CheckList::Menu.new(@filepath, @opts)
  end
rescue CheckList::Exceptions::InvalidOptionError
  CheckList::Helpers.log 'Invalid list option selection'
end

#set_optionsObject

rubocop: disable Layout/HeredocIndentation rubocop: disable Naming/HeredocDelimiterNaming



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/check_list.rb', line 27

def set_options
  Optimist.options do
    version "check-list #{CheckList::Config.version} (c) 2022 Kyle Swaffield"
    banner <<~EOS
        Check-List

    Usage:
    check-list [options] <list name> | <reference name>
    where [options] are:
    EOS
    opt :list, 'checklist name', :type => :string # flag --list, default false
    opt :ref, 'Reference', :type => :string # flag --ref, default false
    opt :view, 'View browser list'
    opt :update, 'Update list'
  end
end

#updateObject



58
59
60
61
62
63
# File 'lib/check_list.rb', line 58

def update
  @update = CheckList::Update.new(@opts, @filepath)
  return update_ref if @opts[:list_given] && @opts[:ref_given]

  update_list
end

#update_listObject



69
70
71
# File 'lib/check_list.rb', line 69

def update_list
  @update.show_lists(nil)
end

#update_refObject



65
66
67
# File 'lib/check_list.rb', line 65

def update_ref
  @update.show_list('', nil)
end

#viewObject



73
74
75
76
77
# File 'lib/check_list.rb', line 73

def view
  return view_ref if @opts[:list_given] && @opts[:ref_given]

  view_list
end

#view_listObject



83
84
85
# File 'lib/check_list.rb', line 83

def view_list
  CheckList::View.new
end

#view_refObject



79
80
81
# File 'lib/check_list.rb', line 79

def view_ref
  puts 'view ref'
end