Class: Ace::Idea::Molecules::IdeaLoader
- Inherits:
-
Object
- Object
- Ace::Idea::Molecules::IdeaLoader
- Defined in:
- lib/ace/idea/molecules/idea_loader.rb
Overview
Loads an idea from its directory, parsing frontmatter + body, and enumerating attachments (images, files).
Class Method Summary collapse
-
.from_scan_result(scan_result) ⇒ Idea?
Load an idea from a ScanResult.
Instance Method Summary collapse
-
#load(dir_path, id: nil, special_folder: nil) ⇒ Idea?
Load an idea from a directory path.
Class Method Details
.from_scan_result(scan_result) ⇒ Idea?
Load an idea from a ScanResult
20 21 22 23 24 |
# File 'lib/ace/idea/molecules/idea_loader.rb', line 20 def self.from_scan_result(scan_result) new.load(scan_result.dir_path, id: scan_result.id, special_folder: scan_result.special_folder) end |
Instance Method Details
#load(dir_path, id: nil, special_folder: nil) ⇒ Idea?
Load an idea from a directory path
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ace/idea/molecules/idea_loader.rb', line 31 def load(dir_path, id: nil, special_folder: nil) return nil unless Dir.exist?(dir_path) # Find the spec file spec_file = Dir.glob(File.join(dir_path, Atoms::IdeaFilePattern::FILE_GLOB)).first return nil unless spec_file # Extract ID from folder name if not provided folder_name = File.basename(dir_path) id ||= extract_id(folder_name) # Parse the spec file content = File.read(spec_file) frontmatter, body = Ace::Support::Items::Atoms::FrontmatterParser.parse(content) # Enumerate attachments (all non-.idea.s.md files in the directory) = (dir_path) # Extract title from frontmatter or body header title = frontmatter["title"] || Ace::Support::Items::Atoms::TitleExtractor.extract(body) || folder_name # Parse creation time created_at = parse_created_at(frontmatter["created_at"], id) # Extract known fields, preserve others in metadata known_keys = %w[id status title tags created_at] = frontmatter.reject { |k, _| known_keys.include?(k) } Models::Idea.new( id: id || frontmatter["id"], status: normalize_status(frontmatter["status"] || "pending"), title: title, tags: Array(frontmatter["tags"]), content: body.to_s.strip, path: dir_path, file_path: spec_file, special_folder: special_folder, created_at: created_at, attachments: , metadata: ) rescue nil end |