kuromd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e982370b2ba03961acd1837f0095a7ebebd68a5ec6529a883924a82752aaac69
4
+ data.tar.gz: 906af716c9199840cfa0707cf6f8d74ca3df1b5de0d577a721e613a7eea327f4
5
+ SHA512:
6
+ metadata.gz: 8cbe8d97458e4bea5cab2a093d0edc107b981e378e9c6bf0682b0ada5e0036fac9370f091ab48150d68798b04c84496f01b031ff412cf7147abbf8e1e5dd3491
7
+ data.tar.gz: d156577c52488bb726fcdd39c27171e21d616737157558c9a01f137e22ab787fc2725b80518018aba0f11795cd4f6cbdc38ab3117353172ca5263154056fb9c4
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in lain.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kuromd (0.0.1)
5
+ activesupport (~> 7.0.6)
6
+ commander (~> 4.6.0)
7
+ dates_from_string (~> 0.9.7)
8
+ dotenv (~> 2.8.1)
9
+ faraday (~> 2.7.10)
10
+ ruby_matter (~> 0.9.8)
11
+ terminal-table (~> 3.0.2)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activesupport (7.0.7)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ tzinfo (~> 2.0)
21
+ ast (2.4.2)
22
+ base64 (0.1.1)
23
+ coderay (1.1.3)
24
+ commander (4.6.0)
25
+ highline (~> 2.0.0)
26
+ concurrent-ruby (1.2.2)
27
+ dates_from_string (0.9.7)
28
+ diff-lcs (1.5.0)
29
+ dotenv (2.8.1)
30
+ faraday (2.7.10)
31
+ faraday-net_http (>= 2.0, < 3.1)
32
+ ruby2_keywords (>= 0.0.4)
33
+ faraday-net_http (3.0.2)
34
+ ffi (1.15.5)
35
+ formatador (1.1.0)
36
+ guard (2.18.0)
37
+ formatador (>= 0.2.4)
38
+ listen (>= 2.7, < 4.0)
39
+ lumberjack (>= 1.0.12, < 2.0)
40
+ nenv (~> 0.1)
41
+ notiffany (~> 0.0)
42
+ pry (>= 0.13.0)
43
+ shellany (~> 0.0)
44
+ thor (>= 0.18.1)
45
+ guard-compat (1.2.1)
46
+ guard-rspec (4.7.3)
47
+ guard (~> 2.1)
48
+ guard-compat (~> 1.1)
49
+ rspec (>= 2.99.0, < 4.0)
50
+ guard-rubocop (1.5.0)
51
+ guard (~> 2.0)
52
+ rubocop (< 2.0)
53
+ highline (2.0.3)
54
+ i18n (1.14.1)
55
+ concurrent-ruby (~> 1.0)
56
+ json (2.6.3)
57
+ language_server-protocol (3.17.0.3)
58
+ listen (3.8.0)
59
+ rb-fsevent (~> 0.10, >= 0.10.3)
60
+ rb-inotify (~> 0.9, >= 0.9.10)
61
+ lumberjack (1.2.9)
62
+ method_source (1.0.0)
63
+ minitest (5.19.0)
64
+ nenv (0.3.0)
65
+ notiffany (0.1.3)
66
+ nenv (~> 0.1)
67
+ shellany (~> 0.0)
68
+ parallel (1.23.0)
69
+ parser (3.2.2.3)
70
+ ast (~> 2.4.1)
71
+ racc
72
+ pry (0.14.2)
73
+ coderay (~> 1.1)
74
+ method_source (~> 1.0)
75
+ racc (1.7.1)
76
+ rainbow (3.1.1)
77
+ rake (13.0.6)
78
+ rb-fsevent (0.11.2)
79
+ rb-inotify (0.10.1)
80
+ ffi (~> 1.0)
81
+ regexp_parser (2.8.1)
82
+ rexml (3.2.6)
83
+ rspec (3.12.0)
84
+ rspec-core (~> 3.12.0)
85
+ rspec-expectations (~> 3.12.0)
86
+ rspec-mocks (~> 3.12.0)
87
+ rspec-core (3.12.2)
88
+ rspec-support (~> 3.12.0)
89
+ rspec-expectations (3.12.3)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.12.0)
92
+ rspec-mocks (3.12.6)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.12.0)
95
+ rspec-support (3.12.1)
96
+ rubocop (1.56.0)
97
+ base64 (~> 0.1.1)
98
+ json (~> 2.3)
99
+ language_server-protocol (>= 3.17.0)
100
+ parallel (~> 1.10)
101
+ parser (>= 3.2.2.3)
102
+ rainbow (>= 2.2.2, < 4.0)
103
+ regexp_parser (>= 1.8, < 3.0)
104
+ rexml (>= 3.2.5, < 4.0)
105
+ rubocop-ast (>= 1.28.1, < 2.0)
106
+ ruby-progressbar (~> 1.7)
107
+ unicode-display_width (>= 2.4.0, < 3.0)
108
+ rubocop-ast (1.29.0)
109
+ parser (>= 3.2.1.0)
110
+ ruby-progressbar (1.13.0)
111
+ ruby2_keywords (0.0.5)
112
+ ruby_matter (0.9.8)
113
+ shellany (0.0.1)
114
+ terminal-table (3.0.2)
115
+ unicode-display_width (>= 1.1.1, < 3)
116
+ thor (1.2.2)
117
+ tzinfo (2.0.6)
118
+ concurrent-ruby (~> 1.0)
119
+ unicode-display_width (2.4.2)
120
+
121
+ PLATFORMS
122
+ x86_64-linux
123
+
124
+ DEPENDENCIES
125
+ guard
126
+ guard-rspec
127
+ guard-rubocop
128
+ kuromd!
129
+ rake (~> 13.0)
130
+ rspec
131
+
132
+ BUNDLED WITH
133
+ 2.3.13
data/Guardfile ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ guard :rspec, cmd: 'rspec' do
21
+ watch(%r{^spec/.+_spec\.rb$})
22
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
23
+ watch('spec/spec_helper.rb') { 'spec' }
24
+ end
25
+
26
+ #guard :rubocop do
27
+ # watch(%r{.+\.rb$})
28
+ # watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
+ #end
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Lain
2
+
3
+ Lain collection of my command-line utilities.
4
+
5
+ ## Installation
6
+
7
+ Erm... this is very much still a todo.
8
+
9
+ ### Configuration File
10
+
11
+ Unless specified using the '-c' flag, kuromd expects the default configuration file in:
12
+
13
+ ```
14
+ ~/.config/kuromd/configuration.yml
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### KuroMD
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rsmacapinlac/lain
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ require 'dotenv'
7
+ require 'fileutils'
8
+
9
+ #require 'lain/version'
10
+ #require 'lain/journal_inbox'
11
+ #require 'lain/journal_folder'
12
+
13
+ require 'active_support'
14
+ require 'active_support/core_ext/integer'
15
+
16
+ RSpec::Core::RakeTask.new(:spec)
17
+
18
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'lain'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config_sample.yml ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ notes:
3
+ # where your notes are kept
4
+ # folder: '~/Nextcloud/Journal/INBOX'
5
+ folder: ''
6
+ one_on_one:
7
+ # where your one on one notes are sent to
8
+ # I currently have it going to an n8n automation
9
+ # url 'https://n8nurl/something'
10
+ url: ''
11
+
data/env.sample ADDED
@@ -0,0 +1 @@
1
+ ENVIRONMENT=development
data/exe/kuroman ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'rubygems'
6
+ require 'commander/import'
7
+
8
+ require 'kuromd/config'
9
+ require 'kuromd/folder'
10
+ require 'kuromd/version'
11
+
12
+ OptionParser.accept Pathname do |path|
13
+ Pathname.new path if path
14
+ end
15
+
16
+ program :name, 'kuroman'
17
+ program :version, Kuromd::VERSION
18
+ program :description, 'These scripts will help you manage things (ie Kuroman - Kuro \'manage\').'
19
+
20
+ global_option('-c', '--config FILE', 'load config data for your commands to use')
21
+
22
+ command :inbox do |c|
23
+ c.syntax = 'kuroman inbox [options]'
24
+ c.summary = 'Process a folder'
25
+ c.description = 'This command will process an \'inbox\' of files.'
26
+ c.example 'description', 'kuroman inbox'
27
+
28
+ c.action do |_args, options|
29
+ # attempt to read config if the global config file is set
30
+ config = Kuromd::Config.new({ config_file: options.config })
31
+ folder = Kuromd::Folder.new({ config: config })
32
+
33
+ if !folder.notes.count.zero?
34
+ # display the table
35
+ say folder.build_table
36
+
37
+ continue = ask("Do you want to process #{folder.notes.count} notes? (y/n)")
38
+ folder.process if continue.downcase! == 'y'
39
+ else
40
+ say('There are no files to process.')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kuromd
4
+ # Super class for all files
5
+ class BaseFile
6
+ attr_accessor :note_type
7
+
8
+ def initialize(params = {}); end
9
+
10
+ def valid?; end
11
+ def process; end
12
+
13
+ # Only one type at the moment, comfortable with hard coding
14
+ def self.assign_file_objs(params = {})
15
+ autoload_files
16
+ objs = []
17
+ objs.push(Kuromd::Journal::File.new(params))
18
+ end
19
+
20
+ # Only one type at the moment, comfortable with hard coding
21
+ def self.cleanup_types
22
+ note_type = []
23
+ note_type.push('Journal file')
24
+ note_type
25
+ end
26
+
27
+ private_class_method def self.autoload_files
28
+ require 'kuromd/journal/file'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kuromd
4
+ # Super class for all Notes
5
+ class BaseNote
6
+ attr_accessor :config, :note_data, :note_type
7
+
8
+ def initialize(params = {})
9
+ raise 'Params required' if params.nil?
10
+
11
+ @config = params[:config]
12
+ @note_data = params[:note_data]
13
+ # ensure path is absolute
14
+ @note_path = @note_data['full_path']
15
+ @note_path = File.expand_path(@note_path)
16
+ end
17
+
18
+ def valid?; end
19
+ def process; end
20
+
21
+ def self.parse_markdown(filepath:)
22
+ parser = RubyMatter.parse(File.read(filepath))
23
+ note_data = parser.data
24
+ note_data['content'] = parser.content
25
+ note_data['full_path'] = filepath
26
+ note_data
27
+ end
28
+
29
+ def self.assign_note_objs(params = {})
30
+ autoload_notes
31
+
32
+ objs = []
33
+ note_data = params[:note_data]
34
+ config = params[:config]
35
+
36
+ # if the note type is not an array, make it one
37
+ # note_type = cleanup_note_types(note_data)
38
+ # puts note_type
39
+
40
+ descendants.each do |descendant|
41
+ obj = descendant.new({ note_data:, config: })
42
+ objs.push(obj) if obj.valid?
43
+ end
44
+
45
+ objs
46
+ end
47
+
48
+ def self.categorize_by_note_objs(params = {})
49
+ autoload_notes
50
+
51
+ note_data = params[:note_data]
52
+ note_objs = params[:note_objs]
53
+
54
+ note_types = []
55
+
56
+ note_objs.each do |note_obj|
57
+ # puts note_obj.valid?
58
+ note_types.push(note_obj.note_type) if note_obj.valid?
59
+ end
60
+
61
+ note_types
62
+
63
+ end
64
+
65
+ private_class_method def self.descendants
66
+ ObjectSpace.each_object(Class).select { |klass| klass < self }
67
+ end
68
+
69
+ private_class_method def self.autoload_notes
70
+ require 'kuromd/one_on_one/note'
71
+ require 'kuromd/journal/note'
72
+ end
73
+
74
+ private_class_method def self.cleanup_note_types(note_data)
75
+ note_type = note_data['note_type']
76
+ unless note_data['note_type'].is_a?(Array)
77
+ note_type = []
78
+ note_type.push(note_data['note_type'])
79
+ note_data['note_type'] = note_type
80
+ note_type = note_data['note_type']
81
+ end
82
+ note_type
83
+ end
84
+
85
+ private
86
+
87
+ def category?
88
+ Kuromd.logger.debug "@note_data['note_type']: #{@note_data['note_type']}, @note_type: #{@note_type} "
89
+ @note_data['note_type'].include?(@note_type)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv'
4
+ require 'yaml'
5
+ require 'kuromd'
6
+
7
+ module Kuromd
8
+ # Handles pulling the configuration from a configuration file.
9
+ class Config
10
+ attr_accessor :params, :config_filepath
11
+
12
+ def configuration_folder
13
+ '~/.config/kuromd'
14
+ end
15
+
16
+ def configuration_file
17
+ 'configuration.yml'
18
+ end
19
+
20
+ def get_config(key)
21
+ if key.nil?
22
+ @params
23
+ else
24
+ @params[key]
25
+ end
26
+ end
27
+
28
+ def initialize(params = {})
29
+ Dotenv.load
30
+
31
+ @config_filepath = File.join(configuration_folder, configuration_file)
32
+ @config_filepath = params[:config_file] unless params[:config_file].nil?
33
+ config_file = File.expand_path(@config_filepath)
34
+ # Kuromd.logger.info "Configuration file: #{config_file}"
35
+
36
+ # replace the configuration with what was passed
37
+ @params = {}
38
+ @params = YAML.load(File.read(config_file)) if File.exist?(config_file)
39
+
40
+ # assume production unless otherwise specified
41
+ @params['environment'] = 'production'
42
+ unless ENV['ENVIRONMENT'].nil?
43
+ @params['environment'] = ENV['ENVIRONMENT']
44
+ end
45
+
46
+ Kuromd.logger.info "Configuration initialized: #{config_file}" unless @params.nil?
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kuromd/config'
4
+
5
+ module Kuromd
6
+ module Configurable
7
+
8
+ @config = nil
9
+
10
+ def set_config(value)
11
+ @config = value
12
+ end
13
+
14
+ def get_config
15
+ @config
16
+ end
17
+
18
+ def configure(params = {})
19
+ if @config.nil?
20
+ set_config(Kuromd::Config.new({ config_file: params[:config_file], key: params[:key] }))
21
+ else
22
+ get_config
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kuromd/basefile'
4
+ require 'kuromd/basenote'
5
+ require 'ruby_matter'
6
+ require 'terminal-table'
7
+
8
+ module Kuromd
9
+ # Represents a folder of stuff, this object should categorize each item
10
+ # and have the ability to process.
11
+ class Folder
12
+ attr_accessor :config, :folder_path, :notes
13
+
14
+ def initialize(params = {})
15
+ raise StandardError, 'Configuration not found' if params[:config].nil?
16
+ @config = params[:config]
17
+
18
+ raise StandardError, 'Journal params not found' if @config.params['journal'].nil?
19
+ raise StandardError, 'Inbox params not found' if @config.params['journal']['inbox'].nil?
20
+
21
+ @folder_path = @config.params['journal']['inbox']
22
+ @folder_path = File.expand_path(@folder_path)
23
+ raise 'Folder not found' unless Dir.exist?(@folder_path)
24
+
25
+ # TODO: test for creating the hash
26
+ @notes = []
27
+ process_files
28
+ end
29
+
30
+ def build_table
31
+ # convert @notes into something that can be used
32
+ rows = []
33
+ count = 1
34
+ @notes.each do |note|
35
+ rows << [count, note[:filename], note[:note_type]]
36
+ count += 1
37
+ end
38
+
39
+ Terminal::Table.new do
40
+ self.headings = ['index', 'Filename', 'Note type']
41
+ self.rows = rows
42
+ end
43
+ end
44
+
45
+ def process
46
+ @notes.each do |note|
47
+ note_objects = note[:note_objs]
48
+ note_objects.each do |note_object|
49
+ note_object.process
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ # TODO: refactor this (rubocop doesn't like it)
57
+ def process_files
58
+ Dir.chdir @folder_path
59
+ Dir.glob('*') do |filename|
60
+ full_path = File.join(@folder_path, filename)
61
+ extension = File.extname(full_path)
62
+
63
+
64
+ # ignore any folders in the identified folder
65
+ unless File.directory?(full_path)
66
+ if extension == '.md'
67
+ # puts filename
68
+ note_data = Kuromd::BaseNote.parse_markdown(filepath: full_path)
69
+ note_objs = Kuromd::BaseNote.assign_note_objs({ note_data:, config: @config })
70
+ note_type = Kuromd::BaseNote.categorize_by_note_objs({ note_data:, note_objs: })
71
+ else
72
+ note_objs = Kuromd::BaseFile.assign_file_objs({full_path:, config: @config })
73
+ note_type = Kuromd::BaseFile.cleanup_types
74
+ end
75
+ @notes.push({ filename:, full_path:, note_type:, note_objs: })
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kuromd/basefile'
4
+ require 'kuromd/configurable'
5
+ require 'kuromd/journal/fileable'
6
+
7
+ module Kuromd
8
+ module Journal
9
+ # Represents a file for a Journal
10
+ # process method will organize the note into it's
11
+ # base folder
12
+ class File < Kuromd::BaseFile
13
+ include Configurable
14
+ include Fileable
15
+
16
+ NOTE_TYPE = 'Journal file'
17
+
18
+ attr_accessor :base_folder, :file_path, :file_date
19
+
20
+ def initialize(params = {})
21
+ super
22
+
23
+ @config = Kuromd::Configurable.get_config
24
+ @base_folder = @config.params['journal']['base_folder']
25
+
26
+ @file_path = params[:full_path]
27
+ @file_date = find_date_from_filename(@file_path)
28
+ Kuromd.logger.info "Initialized Journal File #{@file_path}, #{@file_date}"
29
+ end
30
+
31
+ def cleanup_filename
32
+ filename = ::File.basename(@file_path)
33
+ date_position = filename.index(@file_date)
34
+
35
+ if date_position.zero?
36
+ filename.delete_prefix!("#{@file_date} - ")
37
+ else
38
+ extname = ::File.extname(filename)
39
+ filename.delete_suffix!(" - #{@file_date}#{extname}")
40
+ filename += extname
41
+ end
42
+
43
+ filename
44
+ end
45
+
46
+ def valid?
47
+ # assume valid unless date doesn't exist
48
+ is_valid = true
49
+ is_valid = false if @file_date.nil?
50
+ Kuromd.logger.info "Journal File object valid? #{is_valid}"
51
+
52
+ is_valid
53
+ end
54
+
55
+ def process
56
+ return unless valid?
57
+
58
+ journal_folder = create_journal_folder(base_path: @base_folder, date: @file_date)
59
+ move({ dest_folder: journal_folder,
60
+ source_path: @file_path,
61
+ rename_to: cleanup_filename })
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'dates_from_string'
5
+ require 'fileutils'
6
+
7
+ module Kuromd
8
+ module Journal
9
+ # defines the functions for managing files and folders for journals
10
+ module Fileable
11
+ def create_journal_folder(base_path:, date:)
12
+ date = Date.parse(date.to_s)
13
+ full_date_path = build_date_path(base_path:, date:)
14
+ Kuromd.logger.info "Creating folder #{full_date_path}" if FileUtils.mkdir_p full_date_path
15
+ full_date_path
16
+ end
17
+
18
+ def find_date_from_filename(filepath)
19
+ DatesFromString.new.find_date(filepath)[0]
20
+ end
21
+
22
+ def move(params = {})
23
+ dest_folder = params[:dest_folder]
24
+ source_file = ::File.expand_path(params[:source_path])
25
+
26
+ dest_filename = ::File.basename(source_file)
27
+ dest_filename = params[:rename_to] unless params[:rename_to].nil?
28
+
29
+ destination = ::File.join(dest_folder, dest_filename)
30
+ Kuromd.logger.info "Move: #{source_file} to #{destination}" if FileUtils.mv source_file, destination
31
+ end
32
+
33
+ private
34
+
35
+ def build_date_path(base_path:, date:)
36
+ working_date = date
37
+
38
+ padded_year = working_date.year.to_s
39
+ padded_month = working_date.month.to_s.rjust(2, '0')
40
+ padded_day = working_date.mday.to_s.rjust(2, '0')
41
+
42
+ day_folder = "#{padded_day} #{Date::ABBR_DAYNAMES[working_date.wday]}"
43
+ folder_path = ::File.join(base_path, padded_year, padded_month, day_folder)
44
+
45
+ ::File.expand_path(folder_path)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module Kuromd
6
+ module Journal
7
+ # represents an Inbox folder
8
+ class Inbox
9
+ def initialize(inbox_path:)
10
+ raise 'Inbox path required' if inbox_path.nil? == true
11
+
12
+ @inbox_fullpath = File.expand_path(inbox_path)
13
+ @created = File.exist?(@inbox_fullpath)
14
+ end
15
+
16
+ # creates the inbox folder (if it isn't created)
17
+ def create
18
+ FileUtils.mkdir_p @inbox_fullpath if @created == false
19
+ @created = true
20
+ end
21
+
22
+ # list files in the inbox folder
23
+ def ls
24
+ Dir[@inbox_fullpath]
25
+ end
26
+
27
+ def save(filename:, journal_date: Date.today)
28
+ _filename = File.expand_path(filename)
29
+ _basename = File.basename _filename
30
+ inbox_filename = "#{journal_date} - #{_basename}"
31
+ dest_file = File.join(@inbox_fullpath, inbox_filename)
32
+ FileUtils.mv _filename, dest_file
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kuromd/basenote'
4
+ require 'kuromd/journal/fileable'
5
+ # require 'kuromd/journal/folder'
6
+
7
+ module Kuromd
8
+ module Journal
9
+ # Represents a note for a Journal
10
+ # process method will organize the note into it's
11
+ # base folder
12
+ class Note < Kuromd::BaseNote
13
+ include Fileable
14
+
15
+ attr_accessor :params, :base_folder, :file_path, :file_date
16
+
17
+ NOTE_TYPE = 'Journal'
18
+
19
+ def initialize(params = {})
20
+ super(params)
21
+
22
+ @params = @config.params['journal']
23
+ @base_folder = @params['base_folder']
24
+
25
+ @file_path = params[:full_path]
26
+ @file_date = @note_data['note_date']
27
+
28
+ @note_type = NOTE_TYPE
29
+ Kuromd.logger.info "Journal note initialized: #{@note_data}, #{@params}"
30
+ end
31
+
32
+ def valid?
33
+ # needs a title and a note_date
34
+ is_valid = false
35
+ is_valid = !@note_data['title'].nil? && !@note_data['note_date'].nil? if category?
36
+
37
+ Kuromd.logger.info "Journal Note object valid? #{is_valid}"
38
+ is_valid
39
+ end
40
+
41
+ def process
42
+ return unless valid?
43
+
44
+ Kuromd.logger.info "Processing Journal Note: #{@note_data['title']}, #{@note_data['note_date']}"
45
+ journal_folder = create_journal_folder(base_path: @base_folder, date: @file_date)
46
+ new_filename = "#{@note_data['title']}#{::File.extname(@note_path)}"
47
+
48
+ move({ dest_folder: journal_folder,
49
+ source_path: @note_path,
50
+ rename_to: new_filename })
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kuromd/basenote'
4
+ require 'kuromd/postable'
5
+
6
+ module Kuromd
7
+ module OneOnOne
8
+ # Represents a note for a 1:1
9
+ class Note < Kuromd::BaseNote
10
+ include Postable
11
+
12
+ attr_accessor :params, :note_data, :note_path, :one_on_one_url
13
+ NOTE_TYPE = 'One on one'
14
+
15
+ def initialize(params = {})
16
+ super(params)
17
+ # config = Kuromd::Configurable.get_config
18
+ # @params = config.params['notes']['one_on_one']
19
+ @params = @config.params['notes']['one_on_one']
20
+
21
+ @note_type = NOTE_TYPE
22
+ Kuromd.logger.info "One on one note initialized: #{@note_data}, #{@params}"
23
+ end
24
+
25
+ def valid?
26
+ is_valid = false
27
+
28
+ # has to have the category
29
+ if category?
30
+ # needs a note_date and monica_id
31
+ is_valid = (!@note_data['note_date'].nil? && !@note_data['note_date'].empty?) &&
32
+ !@note_data['monica_id'].nil? &&
33
+ !@note_data['title'].nil?
34
+ end
35
+
36
+ Kuromd.logger.info "One on One note object valid? #{is_valid}"
37
+ is_valid
38
+ end
39
+
40
+ def process
41
+ return unless valid?
42
+
43
+ url = @params['url']
44
+ Kuromd.logger.info "Processing One on one note: #{@note_data['title']}, #{@note_data['note_date']} to #{url}"
45
+
46
+ # Invoke Kuromd::Note::Postable's send method
47
+ send(url, @note_data)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'uri'
5
+
6
+ module Kuromd
7
+ # Post @note_data to a url
8
+ module Postable
9
+ def send(url, note_data)
10
+ uri = URI.parse(url)
11
+
12
+ conn = Faraday.new(
13
+ url: "#{uri.scheme}://#{uri.host}",
14
+ params: note_data,
15
+ headers: { 'Content-Type' => 'application/json' }
16
+ )
17
+
18
+ Kuromd::logger.info "Sending data to #{uri.path}"
19
+ conn.post(uri.path, '')
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kuromd
4
+ VERSION = '0.0.1'
5
+ end
data/lib/kuromd.rb ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv'
4
+ require 'fileutils'
5
+ require_relative 'kuromd/version'
6
+ require 'logger'
7
+
8
+ # top level module to create abstraction and avoid any conflicts
9
+ module Kuromd
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+
13
+ @logger = nil
14
+
15
+ # TODO: create the ability to configure logger
16
+ def self.logger
17
+
18
+ if @logger.nil?
19
+ env = ENV['ENVIRONMENT']
20
+ @logger = init_logger(env)
21
+ # @logger = Logger.new($stdout) unless ENV['ENVIRONMENT'] == 'development'
22
+ # @logger.level = Logger::WARN
23
+ @logger.info 'Logger initialized'
24
+ end
25
+ @logger
26
+ end
27
+
28
+ def self.init_logger(env)
29
+ # create the logs folder if not there
30
+ FileUtils.mkdir_p 'logs'
31
+
32
+ # assume production
33
+ logfile = "logs/#{env}.log"
34
+ logger = Logger.new(logfile)
35
+ if env == 'development'
36
+ logger = Logger.new(STDOUT)
37
+ logger.level = Logger::DEBUG
38
+ end
39
+ logger
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuromd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ritchie Macapinlac
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 7.0.6
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 7.0.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: commander
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.6.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.6.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: dates_from_string
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.7
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.7
111
+ - !ruby/object:Gem::Dependency
112
+ name: dotenv
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.8.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.8.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.7.10
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.7.10
139
+ - !ruby/object:Gem::Dependency
140
+ name: ruby_matter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.9.8
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.9.8
153
+ - !ruby/object:Gem::Dependency
154
+ name: terminal-table
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.2
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 3.0.2
167
+ description:
168
+ email:
169
+ - ritchie@macapinlac.com
170
+ executables:
171
+ - kuroman
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".ruby-version"
176
+ - Gemfile
177
+ - Gemfile.lock
178
+ - Guardfile
179
+ - README.md
180
+ - Rakefile
181
+ - bin/console
182
+ - bin/setup
183
+ - config_sample.yml
184
+ - env.sample
185
+ - exe/kuroman
186
+ - lib/kuromd.rb
187
+ - lib/kuromd/basefile.rb
188
+ - lib/kuromd/basenote.rb
189
+ - lib/kuromd/config.rb
190
+ - lib/kuromd/configurable.rb
191
+ - lib/kuromd/folder.rb
192
+ - lib/kuromd/journal/file.rb
193
+ - lib/kuromd/journal/fileable.rb
194
+ - lib/kuromd/journal/inbox.rb
195
+ - lib/kuromd/journal/note.rb
196
+ - lib/kuromd/one_on_one/note.rb
197
+ - lib/kuromd/postable.rb
198
+ - lib/kuromd/version.rb
199
+ homepage: https://www.macapinlac.com
200
+ licenses:
201
+ - MIT
202
+ metadata:
203
+ homepage_uri: https://www.macapinlac.com
204
+ post_install_message:
205
+ rdoc_options: []
206
+ require_paths:
207
+ - lib
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: 3.2.2
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '0'
218
+ requirements: []
219
+ rubygems_version: 3.4.10
220
+ signing_key:
221
+ specification_version: 4
222
+ summary: These are my personal productivity scripts.
223
+ test_files: []