Module: Wdiff
- Defined in:
- lib/wdiff.rb
Defined Under Namespace
Modules: Helper
Class Method Summary collapse
- .bin_path ⇒ Object
- .diff(old_str, new_str, options = {}) ⇒ Object
- .included(target) ⇒ Object
-
.options_string_from_hash(options = {}) ⇒ Object
TODO - this will fail if option strings include quotes, need to escape quotes automagically.
- .verify_wdiff_in_path ⇒ Object
Instance Method Summary collapse
Class Method Details
.bin_path ⇒ Object
13 14 15 |
# File 'lib/wdiff.rb', line 13 def bin_path 'wdiff' end |
.diff(old_str, new_str, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/wdiff.rb', line 37 def diff(old_str, new_str, ={}) f1, f2 = Tempfile.new('f1'), Tempfile.new('f2') f1.write(old_str); f1.flush f2.write(new_str); f2.flush opt_str = () raw = %x{#{bin_path} #{opt_str} #{f1.path} #{f2.path}} f1.close; f2.close raw end |
.included(target) ⇒ Object
4 5 6 |
# File 'lib/wdiff.rb', line 4 def included(target) verify_wdiff_in_path end |
.options_string_from_hash(options = {}) ⇒ Object
TODO - this will fail if option strings include quotes, need to escape quotes automagically
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wdiff.rb', line 18 def (={}) parts = [] [:inserts].each_with_index do |token, index| token.gsub!(/^\"$/,'\"') if token == '"' parts << ( index.even? ? %Q(--start-insert="#{token}") : %Q(--end-insert="#{token}") ) break if index >= 1 end if [:inserts] [:deletes].each_with_index do |token, index| token.gsub!(/^\"$/,'\"') if token == '"' parts << ( index.even? ? %Q(--start-delete="#{token}") : %Q(--end-delete="#{token}") ) break if index >= 1 end if [:deletes] parts.join(" ") end |
.verify_wdiff_in_path ⇒ Object
8 9 10 11 |
# File 'lib/wdiff.rb', line 8 def verify_wdiff_in_path path = %x{which #{bin_path}} raise "GNU wdiff (http://www.gnu.org/software/wdiff/) not found in $PATH" if path.empty? end |