module StandupMD::Cli::Helpers

Module responsible for reading and writing standup files.

Public Instance Methods

print(entry) click to toggle source

Print an entry to the command line.

@param [StandupMD::Entry] entry

@return [nil]

Private Instance Methods

header(entry) click to toggle source

The header.

@param [StandupMD::Entry] entry

@return [String]

# File lib/standup_md/cli/helpers.rb, line 177
def header(entry)
  '#' * config.file.header_depth + ' ' +
    entry.date.strftime(config.file.header_date_format)
end
load_runtime_preferences(options) click to toggle source

Parses options passed at runtime and concatenates them with the options in the user's preferences file. Reveal source to see options.

@return [Hash]

# File lib/standup_md/cli/helpers.rb, line 45
def load_runtime_preferences(options)
  OptionParser.new do |opts|
    opts.banner = 'The Standup Doctor'
    opts.version = "[StandupMD] #{::StandupMD::Version}"
    opts.on(
      '--current ARRAY', Array,
      "List of current entry's tasks"
    ) { |v| config.entry.current = v }

    opts.on(
      '--previous ARRAY', Array,
      "List of precious entry's tasks"
    ) { |v| config.entry.previous = v }

    opts.on(
      '--impediments ARRAY', Array,
      'List of impediments for current entry'
    ) { |v| config.entry.impediments = v }

    opts.on(
      '--notes ARRAY', Array,
      'List of notes for current entry'
    ) { |v| config.entry.notes = v }

    opts.on(
      '--sub-header-order ARRAY', Array,
      'The order of the sub-headers when writing the file'
    ) { |v| config.file.sub_header_order = v }

    opts.on(
      '-f', '--file-name-format STRING',
      'Date-formattable string to use for standup file name'
    ) { |v| config.file.name_format = v }

    opts.on(
      '-E', '--editor EDITOR',
      'Editor to use for opening standup files'
    ) { |v| config.cli.editor = v }

    opts.on(
      '-d', '--directory DIRECTORY',
      'The directories where standup files are located'
    ) { |v| config.file.directory = v }

    opts.on(
      '-w', '--[no-]write',
      "Write current entry if it doesn't exist. Default is true"
    ) { |v| config.cli.write = v }

    opts.on(
      '-a', '--[no-]auto-fill-previous',
      "Auto-generate 'previous' tasks for new entries. Default is true"
    ) { |v| config.cli.auto_fill_previous = v }

    opts.on(
      '-e', '--[no-]edit',
      'Open the file in the editor. Default is true'
    ) { |v| config.cli.edit = v }

    opts.on(
      '-v', '--[no-]verbose',
      'Verbose output. Default is false.'
    ) { |v| config.cli.verbose = v }

    opts.on(
      '-p', '--print [DATE]',
      'Print current entry.',
      'If DATE is passed, will print entry for DATE, if it exists.',
      'DATE must be in the same format as file-name-format'
    ) do |v|
      config.cli.print = true
      config.cli.date =
        v.nil? ? Date.today : Date.strptime(v, config.file.header_date_format)
    end
  end.parse!(options)
end
new_entry(file) click to toggle source

The entry for today.

@return [StandupMD::Entry]

# File lib/standup_md/cli/helpers.rb, line 126
def new_entry(file)
  entry = file.entries.find(config.cli.date)
  return entry unless entry.nil? && config.cli.date == Date.today

  StandupMD::Entry.new(
    config.cli.date,
    config.entry.current,
    previous_entry(file),
    config.entry.impediments,
    config.entry.notes
  ).tap { |entry| file.entries << entry }
end
prev_entry(entries) click to toggle source

The previous entry.

@param [StandupMD::EntryList] entries

@return [StandupMD::Entry]

# File lib/standup_md/cli/helpers.rb, line 157
def prev_entry(entries)
  return [] if entries.empty?

  entries.last.current
end
prev_file() click to toggle source

The previous month's file.

@return [StandupMD::File]

# File lib/standup_md/cli/helpers.rb, line 167
def prev_file
  StandupMD::File.find_by_date(Date.today.prev_month)
end
previous_entry(file) click to toggle source

The “previous” entries.

@return [Array]

# File lib/standup_md/cli/helpers.rb, line 143
def previous_entry(file)
  return config.entry.previous_entry unless config.cli.auto_fill_previous

  return prev_entry(prev_file.load.entries) if file.new? && prev_file

  prev_entry(file.entries)
end
sub_header(header_type) click to toggle source

The sub-header.

@param [String] header_type

@return [String]

# File lib/standup_md/cli/helpers.rb, line 188
def sub_header(header_type)
  '#' * config.file.sub_header_depth + ' ' +
    config.file.public_send("#{header_type}_header").capitalize
end