Module: RegExRX2MD

Defined in:
lib/regexrx2md.rb,
lib/regexrx2md/regexrx.rb,
lib/regexrx2md/version.rb

Defined Under Namespace

Classes: RegexRX

Constant Summary collapse

DEFAULT_TEMPLATE =
"title: <%= @title %>\n<% if @flags %>\n## Flags\n\n> Flags: `(?<%= @flags %>)`\n\n<%= @flags_desc.snippet_note %>\n<% end %>\n## Regular Expression Search\n\n```ruby\n/<%= @search %>/\n```<% if @replace %>\n\n## Replace\n\n```ruby\n\"<%= @replace.gsub(/\\$/, '\\\\\\\\') %>\"\n```<% end %>\n<% if @source %>\n---\n\n## Test string:\n\n```text\n<%= @source %>\n```\n<% end %>\n\n"
VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.process_file(file, options, template) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/regexrx2md.rb', line 54

def self.process_file(file, options, template)
  # Process the file, generating a new RegexRX object
  rx = RegexRX.new(file)
  # Name the file with output directory, prefix, and title, with .md extension
  filename = File.join(options[:output], "#{options[:prefix]}#{rx.title}.md")
  # Write the file
  File.open(filename, 'w') { |f| f.print(rx.to_markdown(template)) }
  warn "Regex written to #{filename}"
end