class Evertils::Action::Group

Constants

Formatting

Public Class Methods

new(args) click to toggle source

@since 2.2.2

# File lib/evertils/actions/group.rb, line 10
def initialize(args)
  @note_helper = Evertils::Helper::Note.instance
  @args = args
  @note = @note_helper.find_note_by_grammar(grammar.to_s)
  @api_helper = Evertils::Helper::ApiEnmlHandler.new(@config)

  execute
end

Private Instance Methods

execute() click to toggle source

@since 2.2.2

# File lib/evertils/actions/group.rb, line 23
def execute
  return Notify.error('Note not found') if @note.entity.nil?

  group_by
end
grammar() click to toggle source

@since 2.2.2

# File lib/evertils/actions/group.rb, line 31
def grammar
  terms = Grammar.new
  terms.tags = {
    day: Date.today.yday,
    week: Date.today.cweek
  }
  terms.notebook = @args.notebook
  terms.created = Date.new(Date.today.year, 1, 1).strftime('%Y%m%d')
  terms
end
group_by() click to toggle source

@since 2.2.2

# File lib/evertils/actions/group.rb, line 44
def group_by
  grouped_results.each_pair do |job_id, rows|
    Notify.note("#{Formatting.clean(job_id)} - #{rows.size} occurrences") unless job_id.nil?

    rows.each { |row| Notify.info(Formatting.clean(row)) }
  end
end
grouped_results() click to toggle source

@since 2.2.2

# File lib/evertils/actions/group.rb, line 69
def grouped_results
  search_nodes.group_by do |node|
    match = /- (.*)? -/.match(node)
    match[1] unless match.nil?
  end
end
search_nodes() click to toggle source

@since 2.2.2

# File lib/evertils/actions/group.rb, line 54
def search_nodes
  xml = @api_helper.from_str(@note.entity.content)
  target = xml.search('en-note').first
  nodes = []

  target.children.each do |child|
    node = child.children.first.to_s
    nodes.push(Formatting.clean(node)) unless node.empty? || node == '<br/>'
  end

  nodes
end