lib/docx/builder/cleaners.rb in docx-builder-0.2.3 vs lib/docx/builder/cleaners.rb in docx-builder-0.3.0
- old
+ new
@@ -1,41 +1,44 @@
+# frozen_string_literal: true
+
module Docx
- module Builder
- module Cleaners
- def self.starting_tags_without_spaces_cleaner(str)
- str && str.gsub(/\{\s*\{\s*%/, '{{%')
- end
-
- def self.ending_tags_without_spaces_cleaner(str)
- str && str.gsub(/%\s*\}\s*\}/, '%}}')
- end
-
- def self.single_quote_cleaner(str)
- str && str.gsub(/\‘/, '\'').gsub(/\’/, '\'')
- end
-
- def self.var_without_duplicated_spaces_cleaner(str)
- str && str.gsub(/\s+/, ' ')
- end
-
- def self.var_without_spaces_inside_brackets_cleaner(str)
- str && str.gsub(/\[(.*?)\]/) { |match| match.gsub(/\s/, '')}
- end
-
- def self.no_spaces_around_undeline_cleaner(str)
- str && str.gsub(/\s*\_\s*/, "_")
- end
-
- def self.join_dots_and_brackets_cleaner(str)
- str && str.gsub(/\s*\.\s*/, '.').gsub(/\s*\[\s*/, '[').gsub(/\s*\]/, ']')
- end
-
- def self.question_method_cleaner(str)
- if str && str =~ /\A\{\{\s+if\s*(.*?)\s*\?\s+\}\}\Z/
- "{{ if #{$1}\? }}"
- else
- str
- end
- end
+ module Builder
+ # Methods used for cleaning variables inside template
+ module Cleaners
+ def self.starting_tags_without_spaces_cleaner(str)
+ str&.gsub(/\{\s*\{\s*%/, '{{%')
+ end
+
+ def self.ending_tags_without_spaces_cleaner(str)
+ str&.gsub(/%\s*\}\s*\}/, '%}}')
+ end
+
+ def self.single_quote_cleaner(str)
+ str&.gsub(/‘/, '\'')&.gsub(/’/, '\'')
+ end
+
+ def self.var_without_duplicated_spaces_cleaner(str)
+ str&.gsub(/\s+/, ' ')
+ end
+
+ def self.var_without_spaces_inside_brackets_cleaner(str)
+ str&.gsub(/\[(.*?)\]/) { |match| match.gsub(/\s/, '') }
+ end
+
+ def self.no_spaces_around_undeline_cleaner(str)
+ str&.gsub(/\s*_\s*/, '_')
+ end
+
+ def self.join_dots_and_brackets_cleaner(str)
+ str && str.gsub(/\s*\.\s*/, '.').gsub(/\s*\[\s*/, '[').gsub(/\s*\]/, ']')
+ end
+
+ def self.question_method_cleaner(str)
+ if str && str =~ /\A\{\{\s+if\s*(.*?)\s*\?\s+\}\}\Z/
+ "{{ if #{Regexp.last_match(1)}\? }}"
+ else
+ str
end
+ end
end
+ end
end