class Evertils::Controller::Log

Constants

WORDS_PER_LINE

Public Instance Methods

grep(text = nil) click to toggle source

@since 2.2.0

# File lib/evertils/controllers/log.rb, line 39
def grep(text = nil)
  runner = ActionRunner.new
  runner.params = GrepParams.new(text, 'search', 'Daily')
  runner.execute
end
group() click to toggle source

@since 2.2.0

# File lib/evertils/controllers/log.rb, line 47
def group
  runner = ActionRunner.new
  runner.params = GroupParams.new('group', 'Daily')
  runner.execute
end
message(text = nil) click to toggle source

Send arbitrary text to the daily log

# File lib/evertils/controllers/log.rb, line 24
def message(text = nil)
  return Notify.error('A message is required') if text.nil?

  @note = @note_helper.find_note_by_grammar(grammar.to_s)
  text_groups = text.split(' ').each_slice(WORDS_PER_LINE).map do |w|
    w.join(' ')
  end

  return Notify.error("Note not found for grammar '#{grammar}'") if @note.entity.nil?

  modify_with(text_groups)
end
pre_exec() click to toggle source
Calls superclass method Evertils::Controller::Base#pre_exec
# File lib/evertils/controllers/log.rb, line 15
def pre_exec
  super

  @note = nil
  @note_helper = Evertils::Helper::Note.instance
  @api_helper = Evertils::Helper::ApiEnmlHandler.new(@config)
end

Private Instance Methods

grammar() click to toggle source
# File lib/evertils/controllers/log.rb, line 55
def grammar
  terms = Grammar.new
  terms.tags = {
    day: Date.today.yday,
    week: Date.today.cweek
  }
  terms.notebook = :Daily
  terms.created = Date.new(Date.today.year, 1, 1).strftime('%Y%m%d')
  terms
end
modify_with(text) click to toggle source

Update a note with content

# File lib/evertils/controllers/log.rb, line 67
def modify_with(text)
  xml = update_note_content_with(text)

  # remove XML processing definition if it is the second element
  if xml.children[1].is_a?(Nokogiri::XML::ProcessingInstruction)
    xml.children[1].remove
  end

  @note.entity.content = xml.to_s

  Notify.success("Item logged at #{Formatting.current_time}") if @note.update
end
update_note_content_with(text) click to toggle source

@since 2.2.1

# File lib/evertils/controllers/log.rb, line 82
def update_note_content_with(text)
  xml = @api_helper.from_str(@note.entity.content)
  target = xml.search('en-note').first
  job_id = 0
  job_id = text.first.split(' -').first.to_i unless text.first.scan('-').empty?

  text.map! { |l| l.gsub("#{job_id} - ", '')}

  text.each do |line|
    child = "<div>* #{Formatting.current_time} -".dup
    child.concat " #{job_id} -" unless job_id.zero?
    child.concat " #{Formatting.clean(line)}</div>"
    target.add_child(child)
  end

  xml
end