class CopyrightHeader::License
Public Class Methods
new(options)
click to toggle source
# File lib/copyright_header/parser.rb, line 32 def initialize(options) @options = options @lines = load_template.split(/\n/).map { |line| line += "\n" } end
Public Instance Methods
format(comment_open = nil, comment_close = nil, comment_prefix = nil)
click to toggle source
# File lib/copyright_header/parser.rb, line 53 def format(comment_open = nil, comment_close = nil, comment_prefix = nil) comment_open ||= '' comment_close ||= '' comment_prefix ||= '' license = comment_open + @lines.map { |line| (comment_prefix + line).gsub(/\s+\n$/, "\n") }.join() + comment_close license.gsub!(/\\n/, "\n") license end
load_template()
click to toggle source
# File lib/copyright_header/parser.rb, line 42 def load_template if File.exists?(@options[:license_file]) template = ::ERB.new File.new(@options[:license_file]).read, 0, '%' license = template.result(OpenStruct.new(@options).instance_eval { binding }) license = word_wrap(license) license else raise FileNotFoundException.new("Unable to open #{file}") end end
word_wrap(text, max_width = nil)
click to toggle source
# File lib/copyright_header/parser.rb, line 37 def word_wrap(text, max_width = nil) max_width ||= @options[:word_wrap] text.gsub(/(.{1,#{max_width}})(\s|\Z)/, "\\1\n") end