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 =
<<~ENDOFTEMPLATE
  title: <%= @title %>
  <% if @flags %>
  ## Flags

  > Flags: `(?<%= @flags %>)`

  <%= @flags_desc.snippet_note %>
  <% end %>
  ## Regular Expression Search

  ```ruby
  /<%= @search %>/
  ```<% if @replace %>

  ## Replace

  ```ruby
  "<%= @replace.gsub(/\$/, '\\\\') %>"
  ```<% end %>
  <% if @source %>
  ---

  ## Test string:

  ```text
  <%= @source %>
  ```
  <% end %>

ENDOFTEMPLATE
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