Class: DocxReplace::Doc
- Inherits:
-
Object
- Object
- DocxReplace::Doc
- Defined in:
- lib/docx_replace.rb
Instance Method Summary collapse
- #commit(new_path = nil) ⇒ Object
-
#initialize(path, temp_dir = nil) ⇒ Doc
constructor
A new instance of Doc.
- #matches(pattern) ⇒ Object
- #replace(pattern, replacement, multiple_occurrences = false) ⇒ Object
- #unique_matches(pattern) ⇒ Object (also: #uniq_matches)
Constructor Details
#initialize(path, temp_dir = nil) ⇒ Doc
Returns a new instance of Doc.
7 8 9 10 11 |
# File 'lib/docx_replace.rb', line 7 def initialize(path, temp_dir=nil) @zip_file = Zip::File.new(path) @temp_dir = temp_dir read_docx_file end |
Instance Method Details
#commit(new_path = nil) ⇒ Object
32 33 34 |
# File 'lib/docx_replace.rb', line 32 def commit(new_path=nil) write_back_to_file(new_path) end |
#matches(pattern) ⇒ Object
21 22 23 |
# File 'lib/docx_replace.rb', line 21 def matches(pattern) @document_content.scan(pattern).map{|match| match.first} end |
#replace(pattern, replacement, multiple_occurrences = false) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/docx_replace.rb', line 13 def replace(pattern, replacement, multiple_occurrences=false) if multiple_occurrences @document_content.gsub!(pattern, replacement) else @document_content.sub!(pattern, replacement) end end |
#unique_matches(pattern) ⇒ Object Also known as: uniq_matches
25 26 27 |
# File 'lib/docx_replace.rb', line 25 def unique_matches(pattern) matches(pattern) end |