Class: Breakdown::Processor
- Inherits:
-
Object
- Object
- Breakdown::Processor
- Defined in:
- lib/breakdown.rb
Overview
Valid markers:
* * *
***
*****
- - -
---------------------------------------
Instance Method Summary collapse
-
#initialize ⇒ Processor
constructor
A new instance of Processor.
- #process(filename, output_dir, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Processor
Returns a new instance of Processor.
35 36 37 |
# File 'lib/breakdown.rb', line 35 def initialize @autonum_count = {} end |
Instance Method Details
#process(filename, output_dir, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/breakdown.rb', line 39 def process(filename, output_dir, ={}) # Preconditions raise "No such file: #{filename}" unless File.exist?(filename) raise "Can't read file: #{filename}" unless File.readable?(filename) # SMELL output_dir is used in two different variables = {:extension => 'md', :output_dir => output_dir}.merge() FileUtils.mkdir_p output_dir # Ensure we have somewhere to put our files f = File.open(filename) begin each_section(f) do |title, text| command_match = title.match(/[:](?<command>.[a-z]*)(\s(?<params>.*)|$)/) if command_match section = self.send(command_match[:command], command_match[:params], text, ) else section = {:title => title, :text => text} end yield section if block_given? write_section(section, ) unless section.nil? end #rescue f.close # SMELL silent fail end end |