Class: Kuromd::Folder

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

Overview

Represents a folder of stuff, this object should categorize each item and have the ability to process.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Folder

Returns a new instance of Folder.

Raises:

  • (StandardError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kuromd/folder.rb', line 14

def initialize(params = {})
  raise StandardError, 'Configuration not found' if params[:config].nil?
  @config = params[:config]

  raise StandardError, 'Journal params not found' if @config.params['journal'].nil?
  raise StandardError, 'Inbox params not found' if @config.params['journal']['inbox'].nil?

  @folder_path = @config.params['journal']['inbox']
  @folder_path = File.expand_path(@folder_path)
  raise 'Folder not found' unless Dir.exist?(@folder_path)

  # TODO: test for creating the hash
  @notes = []
  process_files
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



12
13
14
# File 'lib/kuromd/folder.rb', line 12

def config
  @config
end

#folder_pathObject

Returns the value of attribute folder_path.



12
13
14
# File 'lib/kuromd/folder.rb', line 12

def folder_path
  @folder_path
end

#notesObject

Returns the value of attribute notes.



12
13
14
# File 'lib/kuromd/folder.rb', line 12

def notes
  @notes
end

Instance Method Details

#build_tableObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kuromd/folder.rb', line 30

def build_table
  # convert @notes into something that can be used
  rows = []
  count = 1
  @notes.each do |note|
    rows << [count, note[:filename], note[:note_type]]
    count += 1
  end

  Terminal::Table.new do
    self.headings = ['index', 'Filename', 'Note type']
    self.rows = rows
  end
end

#processObject



45
46
47
48
49
50
51
52
# File 'lib/kuromd/folder.rb', line 45

def process
  @notes.each do |note|
    note_objects = note[:note_objs]
    note_objects.each do |note_object|
      note_object.process
    end
  end
end