Module: Copywriter::Regex
Instance Method Summary collapse
-
#accepted_name?(filename) ⇒ Boolean
Returns true if this is a file that we will update, (otherwise false).
-
#update_copyright(year, old_content) ⇒ String
Updates copyright using regex, then commits it.
Instance Method Details
#accepted_name?(filename) ⇒ Boolean
Returns true if this is a file that we will update, (otherwise false).
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/github-copywriter/regex.rb', line 17 def accepted_name?(filename) filename = File.basename(filename) names = ["readme", "license"] extensions = [".md", ".txt", ".html"] if names.include? filename.downcase then return true end if extensions.include? File.extname(filename.downcase) then return true end return false end |
#update_copyright(year, old_content) ⇒ String
Updates copyright using regex, then commits it.
up to date.
35 36 37 38 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/github-copywriter/regex.rb', line 35 def update_copyright(year, old_content) # Have to do separate assignments b/c ruby shares strings, # TODO: find a way around this # Do the substitution # # Matches: # Copyright 2014 # copyright 2014 # # Copyright (C) 2014 # copyright (c) 2014 # Copyright © 2014 # copyright © 2014 # # (c) 2014 # (C) 2014 # © 2014 begin new_content = \ old_content.gsub(/([Cc]opyright( \([Cc]\)| ©)?|\([Cc]\)|©) \d{4}/, "\\1 #{year}") rescue # try w/o "©" symbol if we had errors new_content = \ old_content.gsub(/([Cc]opyright( \([Cc]\))?|\([Cc]\)) \d{4}/, "\\1 #{year}") end # Only commit if we need to if new_content != old_content then return new_content else return nil end end |