class StandupMD::Parsers::Markdown
Parser and renderer for the markdown standup format.
Attributes
Access to file configuration.
@return [StandupMD::Config::File]
Public Class Methods
Source
# File lib/standup_md/parsers/markdown.rb, line 30 def initialize(config = StandupMD.config.file) @config = config end
Constructs an instance of StandupMD::Parsers::Markdown.
@param [StandupMD::Config::File] config
Public Instance Methods
Source
# File lib/standup_md/parsers/markdown.rb, line 40 def parse(text) entry_list = EntryList.new record = nil section = nil text.to_s.each_line do |line| line.chomp! next if line.strip.empty? if header?(line) entry_list << entry(record) if record record = {title: title(line), sections: {}} section = section(:notes) record[:sections][:notes] = section elsif sub_header?(line) section = section(section_type(line)) record[:sections][section.type] = section else section << task(line) end end entry_list << entry(record) if record entry_list.sort rescue => e raise Error, "Markdown malformation: #{e.message}" end
Parses entries from markdown text.
@param [String] text
@return [StandupMD::EntryList]
Source
# File lib/standup_md/parsers/markdown.rb, line 76 def render(entries, start_date:, end_date:) entries.filter(start_date, end_date).sort_reverse.map do |entry| render_entry(entry) end.join end
Renders entries as markdown text.
@param [StandupMD::EntryList] entries @param [Date] start_date @param [Date] end_date
@return [String]
Source
# File lib/standup_md/parsers/markdown.rb, line 88 def render_entry(entry) lines = [entry_header(entry)] config.sub_header_order.each do |type| section = Section.new(type, entry.public_send("#{type}_tasks")) next if section.empty? lines << section_header(type) section.tasks.each { |task| lines << task_line(task) } end lines << "" lines.join("\n") + "\n" end
Renders a single entry as markdown text.
@param [StandupMD::Entry] entry
@return [String]