Module: Ariadna::Tools::Utilities
- Defined in:
- lib/ariadna/tools/utilities.rb
Class Method Summary collapse
- .current_timestamp(argv, raw: false) ⇒ Object
- .generate_slug(argv, raw: false) ⇒ Object
- .list_todos(argv, raw: false) ⇒ Object
- .todo_complete(filename, raw: false) ⇒ Object
- .todo_dispatch(argv, raw: false) ⇒ Object
- .verify_path_exists(argv, raw: false) ⇒ Object
Class Method Details
.current_timestamp(argv, raw: false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ariadna/tools/utilities.rb', line 15 def self.(argv, raw: false) format = argv.first || "full" now = Time.now.utc result = case format when "date" now.strftime("%Y-%m-%d") when "filename" now.strftime("%Y-%m-%dT%H-%M-%S") else now.iso8601 end Output.json({ timestamp: result }, raw: raw, raw_value: result) end |
.generate_slug(argv, raw: false) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/ariadna/tools/utilities.rb', line 7 def self.generate_slug(argv, raw: false) text = argv.first Output.error("text required for slug generation") unless text slug = text.downcase.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "") Output.json({ slug: slug }, raw: raw, raw_value: slug) end |
.list_todos(argv, raw: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ariadna/tools/utilities.rb', line 31 def self.list_todos(argv, raw: false) area = argv.first cwd = Dir.pwd pending_dir = File.join(cwd, ".ariadna_planning", "todos", "pending") count = 0 todos = [] if File.directory?(pending_dir) Dir[File.join(pending_dir, "*.md")].each do |file| content = File.read(file) created = content[/^created:\s*(.+)$/i, 1]&.strip || "unknown" title = content[/^title:\s*(.+)$/i, 1]&.strip || "Untitled" todo_area = content[/^area:\s*(.+)$/i, 1]&.strip || "general" next if area && todo_area != area count += 1 todos << { file: File.basename(file), created: created, title: title, area: todo_area, path: File.join(".ariadna_planning", "todos", "pending", File.basename(file)) } end end Output.json({ count: count, todos: todos }, raw: raw, raw_value: count.to_s) end |
.todo_complete(filename, raw: false) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ariadna/tools/utilities.rb', line 87 def self.todo_complete(filename, raw: false) Output.error("filename required") unless filename cwd = Dir.pwd pending = File.join(cwd, ".ariadna_planning", "todos", "pending", filename) completed_dir = File.join(cwd, ".ariadna_planning", "todos", "completed") unless File.exist?(pending) Output.json({ completed: false, reason: "not_found" }, raw: raw, raw_value: "false") return end FileUtils.mkdir_p(completed_dir) FileUtils.mv(pending, File.join(completed_dir, filename)) Output.json({ completed: true, file: filename }, raw: raw, raw_value: "true") end |
.todo_dispatch(argv, raw: false) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/ariadna/tools/utilities.rb', line 77 def self.todo_dispatch(argv, raw: false) subcommand = argv.shift case subcommand when "complete" todo_complete(argv.first, raw: raw) else Output.error("Unknown todo subcommand. Available: complete") end end |
.verify_path_exists(argv, raw: false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ariadna/tools/utilities.rb', line 62 def self.verify_path_exists(argv, raw: false) target_path = argv.first Output.error("path required for verification") unless target_path cwd = Dir.pwd full_path = File.absolute_path?(target_path) ? target_path : File.join(cwd, target_path) if File.exist?(full_path) type = File.directory?(full_path) ? "directory" : "file" Output.json({ exists: true, type: type }, raw: raw, raw_value: "true") else Output.json({ exists: false, type: nil }, raw: raw, raw_value: "false") end end |