Class: Ace::Docs::Models::AnalysisReport
- Inherits:
-
Object
- Object
- Ace::Docs::Models::AnalysisReport
- Defined in:
- lib/ace/docs/models/analysis_report.rb
Overview
Data model for analysis reports
Instance Attribute Summary collapse
-
#analysis ⇒ Object
Returns the value of attribute analysis.
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#generated ⇒ Object
Returns the value of attribute generated.
-
#since ⇒ Object
Returns the value of attribute since.
-
#statistics ⇒ Object
Returns the value of attribute statistics.
Class Method Summary collapse
-
.load_from_file(filepath) ⇒ AnalysisReport
Load report from file.
- .parse_documents(doc_list) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ AnalysisReport
constructor
A new instance of AnalysisReport.
-
#save_to_cache(cache_dir = nil) ⇒ String
Save report to cache directory.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_markdown ⇒ String
Convert report to markdown format.
Constructor Details
#initialize(attributes = {}) ⇒ AnalysisReport
Returns a new instance of AnalysisReport.
14 15 16 17 18 19 20 |
# File 'lib/ace/docs/models/analysis_report.rb', line 14 def initialize(attributes = {}) @generated = attributes[:generated] || Time.now.utc.iso8601 @since = attributes[:since] @documents = attributes[:documents] || [] @analysis = attributes[:analysis] @statistics = attributes[:statistics] || {} end |
Instance Attribute Details
#analysis ⇒ Object
Returns the value of attribute analysis.
12 13 14 |
# File 'lib/ace/docs/models/analysis_report.rb', line 12 def analysis @analysis end |
#documents ⇒ Object
Returns the value of attribute documents.
12 13 14 |
# File 'lib/ace/docs/models/analysis_report.rb', line 12 def documents @documents end |
#generated ⇒ Object
Returns the value of attribute generated.
12 13 14 |
# File 'lib/ace/docs/models/analysis_report.rb', line 12 def generated @generated end |
#since ⇒ Object
Returns the value of attribute since.
12 13 14 |
# File 'lib/ace/docs/models/analysis_report.rb', line 12 def since @since end |
#statistics ⇒ Object
Returns the value of attribute statistics.
12 13 14 |
# File 'lib/ace/docs/models/analysis_report.rb', line 12 def statistics @statistics end |
Class Method Details
.load_from_file(filepath) ⇒ AnalysisReport
Load report from file
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ace/docs/models/analysis_report.rb', line 67 def self.load_from_file(filepath) content = File.read(filepath) # Parse YAML frontmatter if content =~ /\A---\n(.*?)\n---\n(.*)/m frontmatter = YAML.safe_load(Regexp.last_match(1)) body = Regexp.last_match(2) new( generated: frontmatter["generated"], since: frontmatter["since"], documents: parse_documents(frontmatter["document_list"]), analysis: body.strip, statistics: frontmatter["statistics"] || {} ) else # No frontmatter, treat entire content as analysis new(analysis: content) end end |
.parse_documents(doc_list) ⇒ Object
112 113 114 115 116 |
# File 'lib/ace/docs/models/analysis_report.rb', line 112 def self.parse_documents(doc_list) return [] unless doc_list doc_list.map { |path| {path: path} } end |
Instance Method Details
#save_to_cache(cache_dir = nil) ⇒ String
Save report to cache directory
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ace/docs/models/analysis_report.rb', line 40 def save_to_cache(cache_dir = nil) cache_dir ||= Ace::Docs.config["cache_dir"] || ".ace-local/docs" FileUtils.mkdir_p(cache_dir) compact_id = Ace::B36ts.encode(Time.now) filename = "analysis-#{compact_id}.md" filepath = File.join(cache_dir, filename) File.write(filepath, to_markdown) filepath end |
#to_h ⇒ Hash
Convert to hash
54 55 56 57 58 59 60 61 62 |
# File 'lib/ace/docs/models/analysis_report.rb', line 54 def to_h { generated: @generated, since: @since, documents: documents_list, analysis: @analysis, statistics: @statistics } end |
#to_markdown ⇒ String
Convert report to markdown format
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ace/docs/models/analysis_report.rb', line 24 def to_markdown frontmatter = build_frontmatter body = @analysis || "No analysis available" <<~MARKDOWN --- #{frontmatter.to_yaml.strip} --- #{body} MARKDOWN end |