class OrgmodeCodeExractor::Main
Public Instance Methods
extract(*orgfiles)
click to toggle source
# File lib/orgmode-code-extractor.rb, line 19 def extract(*orgfiles) todir = options[:todir] missingfile = options[:missing] name = ext = output = nil orgfiles.each do |ofile| rawlines(ofile) do |lines| lines.each do |line| case line when /^[[:space:]]*\#\+(name|NAME):[[:space:]]+([[:graph:]]+)[[:space:]]*/ name = $~[2] if output.nil? when /^[[:space:]]*\#\+(begin_src|BEGIN_SRC)[[:space:]]+([[:graph:]]+)?[[:space:]]*/ # open the file for the code block ext = $~[2] || "src" begin unless name.nil? output = open(File::expand_path("#{name}.#{ext}", todir), 'w') else output = open(File::expand_path("#{missingfile}.#{ext}", todir), 'a') end rescue => e puts "??? Problem creating #{name}.#{ext} in directory #{todir}: #{e}" end when /^[[:space:]]*\#\+(end_src|END_SRC)[[:space:]]*/ output.close unless output.nil? name = ext = output = nil else output.write(line) unless output.nil? end end end end end
version()
click to toggle source
# File lib/orgmode-code-extractor.rb, line 12 def version puts SemVer.find.format "%M.%m.%p%s" end
Private Instance Methods
rawlines(orgfile) { |readlines| ... }
click to toggle source
# File lib/orgmode-code-extractor.rb, line 53 def rawlines(orgfile) open(orgfile) do |fd| yield fd.readlines end end