Class: Kuromd::BaseNote

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

Overview

Super class for all Notes

Direct Known Subclasses

Journal::Note, OneOnOne::Note

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BaseNote

Returns a new instance of BaseNote.



8
9
10
11
12
13
14
15
16
# File 'lib/kuromd/basenote.rb', line 8

def initialize(params = {})
  raise 'Params required' if params.nil?

  @config = params[:config]
  @note_data = params[:note_data]
  # ensure path is absolute
  @note_path = @note_data['full_path']
  @note_path = File.expand_path(@note_path)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/kuromd/basenote.rb', line 6

def config
  @config
end

#note_dataObject

Returns the value of attribute note_data.



6
7
8
# File 'lib/kuromd/basenote.rb', line 6

def note_data
  @note_data
end

#note_typeObject

Returns the value of attribute note_type.



6
7
8
# File 'lib/kuromd/basenote.rb', line 6

def note_type
  @note_type
end

Class Method Details

.assign_note_objs(params = {}) ⇒ Object



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

def self.assign_note_objs(params = {})
  autoload_notes

  objs = []
  note_data = params[:note_data]
  config = params[:config]

  # if the note type is not an array, make it one
  # note_type = cleanup_note_types(note_data)
  # puts note_type

  descendants.each do |descendant|
    obj = descendant.new({ note_data:, config: })
    objs.push(obj) if obj.valid?
  end

  objs
end

.categorize_by_note_objs(params = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kuromd/basenote.rb', line 48

def self.categorize_by_note_objs(params = {})
  autoload_notes

  note_data = params[:note_data]
  note_objs = params[:note_objs]

  note_types = []

  note_objs.each do |note_obj|
    # puts note_obj.valid?
    note_types.push(note_obj.note_type) if note_obj.valid?
  end

  note_types

end

.parse_markdown(filepath:) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/kuromd/basenote.rb', line 21

def self.parse_markdown(filepath:)
  parser = RubyMatter.parse(File.read(filepath))
  note_data = parser.data
  note_data['content'] = parser.content
  note_data['full_path'] = filepath
  note_data
end

Instance Method Details

#processObject



19
# File 'lib/kuromd/basenote.rb', line 19

def process; end

#valid?Boolean

Returns:

  • (Boolean)


18
# File 'lib/kuromd/basenote.rb', line 18

def valid?; end