Class: StandupMD::Parsers::Markdown
- Inherits:
-
Object
- Object
- StandupMD::Parsers::Markdown
- Defined in:
- lib/standup_md/parsers/markdown.rb
Overview
Parser and renderer for the markdown standup format.
Instance Attribute Summary collapse
-
#config ⇒ StandupMD::Config::File
readonly
Access to file configuration.
Instance Method Summary collapse
-
#initialize(config = StandupMD.config.file) ⇒ Markdown
constructor
Constructs an instance of
StandupMD::Parsers::Markdown. -
#read(file_name) ⇒ StandupMD::EntryList
Reads entries from a markdown standup file.
-
#task_line(task) ⇒ String
Renders a task as a markdown list item.
-
#write(file_name, entries, start_date:, end_date:) ⇒ Boolean
Writes entries to a markdown standup file.
Constructor Details
Instance Attribute Details
#config ⇒ StandupMD::Config::File (readonly)
Access to file configuration.
19 20 21 |
# File 'lib/standup_md/parsers/markdown.rb', line 19 def config @config end |
Instance Method Details
#read(file_name) ⇒ StandupMD::EntryList
Reads entries from a markdown standup file.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/standup_md/parsers/markdown.rb', line 35 def read(file_name) entry_list = EntryList.new record = nil section = nil ::File.foreach(file_name) 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 "File malformation: #{e}" end |
#task_line(task) ⇒ String
Renders a task as a markdown list item.
94 95 96 |
# File 'lib/standup_md/parsers/markdown.rb', line 94 def task_line(task) build_task(task).to_markdown end |
#write(file_name, entries, start_date:, end_date:) ⇒ Boolean
Writes entries to a markdown standup file.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/standup_md/parsers/markdown.rb', line 72 def write(file_name, entries, start_date:, end_date:) ::File.open(file_name, "w") do |f| entries.filter(start_date, end_date).sort_reverse.each do |entry| f.puts Title.new(entry.date).to_markdown config.sub_header_order.each do |attr| section = Section.new(attr, entry.public_send("#{attr}_tasks")) next if section.empty? f.puts section.to_markdown end f.puts end end true end |