Class: WritersRoom::ProjectState
- Inherits:
-
Object
- Object
- WritersRoom::ProjectState
- Defined in:
- lib/writers_room/project_state.rb
Overview
Summarizes the current state of a project: what exists, what's missing, what's in progress, and what stage the project is in.
Instance Attribute Summary collapse
-
#medium ⇒ Object
readonly
Returns the value of attribute medium.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Instance Method Summary collapse
- #element_counts ⇒ Object
- #empty_dirs ⇒ Object
- #has_characters? ⇒ Boolean
- #has_concept? ⇒ Boolean
-
#initialize(project_path, medium: nil) ⇒ ProjectState
constructor
A new instance of ProjectState.
- #missing_dirs ⇒ Object
- #summary ⇒ Object
- #workflow_stage ⇒ Object
Constructor Details
#initialize(project_path, medium: nil) ⇒ ProjectState
Returns a new instance of ProjectState.
9 10 11 12 13 |
# File 'lib/writers_room/project_state.rb', line 9 def initialize(project_path, medium: nil) @project_path = File.(project_path) = ProjectMetadata.new(@project_path) @medium = medium || MediumRegistry.find(.medium.to_sym) end |
Instance Attribute Details
#medium ⇒ Object (readonly)
Returns the value of attribute medium.
7 8 9 |
# File 'lib/writers_room/project_state.rb', line 7 def medium @medium end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/writers_room/project_state.rb', line 7 def end |
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
7 8 9 |
# File 'lib/writers_room/project_state.rb', line 7 def project_path @project_path end |
Instance Method Details
#element_counts ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/writers_room/project_state.rb', line 15 def element_counts counts = {} @medium.scaffolded_dirs.each do |dir| dir_path = File.join(@project_path, dir) next unless Dir.exist?(dir_path) files = Dir.glob(File.join(dir_path, "*.md")).reject { |f| f.match?(/_v\d+\.md\z/) } counts[dir] = files.count if files.count > 0 end counts end |
#empty_dirs ⇒ Object
32 33 34 35 36 37 |
# File 'lib/writers_room/project_state.rb', line 32 def empty_dirs @medium.scaffolded_dirs.select do |dir| dir_path = File.join(@project_path, dir) Dir.exist?(dir_path) && Dir.glob(File.join(dir_path, "*.md")).empty? end end |
#has_characters? ⇒ Boolean
43 44 45 46 |
# File 'lib/writers_room/project_state.rb', line 43 def has_characters? dir = File.join(@project_path, "characters") Dir.exist?(dir) && !Dir.glob(File.join(dir, "*.md")).empty? end |
#has_concept? ⇒ Boolean
39 40 41 |
# File 'lib/writers_room/project_state.rb', line 39 def has_concept? !.concept.to_s.strip.empty? end |
#missing_dirs ⇒ Object
26 27 28 29 30 |
# File 'lib/writers_room/project_state.rb', line 26 def missing_dirs @medium.scaffolded_dirs.reject do |dir| Dir.exist?(File.join(@project_path, dir)) end end |
#summary ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/writers_room/project_state.rb', line 56 def summary counts = element_counts lines = [] lines << "Project: #{@metadata.name}" unless .name.to_s.empty? lines << "Medium: #{@medium.label}" lines << "Stage: #{workflow_stage}" if counts.any? lines << "Elements:" counts.each { |dir, count| lines << " #{dir}: #{count}" } end empty = empty_dirs if empty.any? lines << "Empty: #{empty.join(', ')}" end lines.join("\n") end |
#workflow_stage ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/writers_room/project_state.rb', line 48 def workflow_stage counts = element_counts return :empty if counts.empty? && !has_concept? return :concept_only if counts.empty? && has_concept? return :populating if counts.values.sum < 5 :developing end |