Class: WritersRoom::ProjectMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/writers_room/project_metadata.rb

Overview

Manages project metadata including concept, arcs, and timeline. Uses .md files with YAML front matter.

Constant Summary collapse

DEFAULT_METADATA =
{
  "name" => "",
  "concept" => "",
  "medium" => "dialog",
  "created_at" => Time.now.to_s,
  "story_arcs" => [],
  "timeline" => []
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path) ⇒ ProjectMetadata

Returns a new instance of ProjectMetadata.



21
22
23
24
25
# File 'lib/writers_room/project_metadata.rb', line 21

def initialize(project_path)
  @project_path = project_path
  @path = File.join(project_path, "project.md")
  @data = 
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/writers_room/project_metadata.rb', line 10

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/writers_room/project_metadata.rb', line 10

def path
  @path
end

Class Method Details

.create(project_path, name:, concept: "", medium: "dialog") ⇒ Object

Create new project metadata



56
57
58
59
60
61
62
63
64
# File 'lib/writers_room/project_metadata.rb', line 56

def self.create(project_path, name:, concept: "", medium: "dialog")
   = new(project_path)
  .data["name"] = name
  .data["concept"] = concept
  .data["medium"] = medium.to_s
  .data["created_at"] = Time.now.to_s
  .save
  
end

Instance Method Details

#add_story_arc(arc) ⇒ Object



98
99
100
101
102
# File 'lib/writers_room/project_metadata.rb', line 98

def add_story_arc(arc)
  @data["story_arcs"] ||= []
  @data["story_arcs"] << arc
  save
end

#add_timeline_entry(entry) ⇒ Object



108
109
110
111
112
# File 'lib/writers_room/project_metadata.rb', line 108

def add_timeline_entry(entry)
  @data["timeline"] ||= []
  @data["timeline"] << entry
  save
end

#conceptObject



76
77
78
# File 'lib/writers_room/project_metadata.rb', line 76

def concept
  @data["concept"] || @body || ""
end

#concept=(value) ⇒ Object



80
81
82
83
# File 'lib/writers_room/project_metadata.rb', line 80

def concept=(value)
  @data["concept"] = value
  save
end

#load_metadataObject

Load metadata from file



28
29
30
31
32
33
34
35
# File 'lib/writers_room/project_metadata.rb', line 28

def 
  return .dup unless File.exist?(path)

  load_from_md
rescue StandardError => e
  warn "Error loading metadata from #{path}: #{e.message}"
  .dup
end

#mediumObject



85
86
87
# File 'lib/writers_room/project_metadata.rb', line 85

def medium
  @data["medium"] || "dialog"
end

#medium=(value) ⇒ Object



89
90
91
92
# File 'lib/writers_room/project_metadata.rb', line 89

def medium=(value)
  @data["medium"] = value.to_s
  save
end

#nameObject

Get/set methods



67
68
69
# File 'lib/writers_room/project_metadata.rb', line 67

def name
  @data["name"]
end

#name=(value) ⇒ Object



71
72
73
74
# File 'lib/writers_room/project_metadata.rb', line 71

def name=(value)
  @data["name"] = value
  save
end

#save(metadata = @data) ⇒ Object

Save metadata to file as .md with front matter



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/writers_room/project_metadata.rb', line 38

def save( = @data)
  FileUtils.mkdir_p(File.dirname(@path))

  # Extract body content (description, etc.) from metadata
  body = .delete("body") || .delete(:body) || build_body()
  meta = .reject { |k, _| k.to_s == "body" }

  content = FrontMatter.dump(meta, body)
  File.write(@path, content)

  @data = 
  true
rescue StandardError => e
  warn "Error saving metadata to #{@path}: #{e.message}"
  false
end

#story_arcsObject



94
95
96
# File 'lib/writers_room/project_metadata.rb', line 94

def story_arcs
  @data["story_arcs"] || []
end

#timelineObject



104
105
106
# File 'lib/writers_room/project_metadata.rb', line 104

def timeline
  @data["timeline"] || []
end