Module: TheLocal::Format
- Defined in:
- lib/the_local/format.rb
Constant Summary collapse
- FRONT_MATTER_KEYS =
%w[name description tools scope].freeze
- SECTIONS =
["## What", "## Interface", "## How to use it", "## Conventions"].freeze
Class Method Summary collapse
- .missing_keys(markdown) ⇒ Object
- .missing_sections(markdown) ⇒ Object
- .problems(markdown) ⇒ Object
- .section(markdown, heading) ⇒ Object
Class Method Details
.missing_keys(markdown) ⇒ Object
17 18 19 20 |
# File 'lib/the_local/format.rb', line 17 def self.missing_keys(markdown) FRONT_MATTER_KEYS.reject { |key| markdown.match?(/^#{key}:/) } .map { |key| "missing key: #{key}" } end |
.missing_sections(markdown) ⇒ Object
22 23 24 25 |
# File 'lib/the_local/format.rb', line 22 def self.missing_sections(markdown) SECTIONS.reject { |section| markdown.include?(section) } .map { |section| "missing section: #{section}" } end |
.problems(markdown) ⇒ Object
13 14 15 |
# File 'lib/the_local/format.rb', line 13 def self.problems(markdown) missing_keys(markdown) + missing_sections(markdown) end |
.section(markdown, heading) ⇒ Object
9 10 11 |
# File 'lib/the_local/format.rb', line 9 def self.section(markdown, heading) markdown[/^#{Regexp.escape(heading)}$\n(.*?)(?=^## |\z)/m, 1].to_s end |