Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iminside/diffing
Gem for calculating two strings difference
https://github.com/iminside/diffing
Last synced: 1 day ago
JSON representation
Gem for calculating two strings difference
- Host: GitHub
- URL: https://github.com/iminside/diffing
- Owner: iminside
- License: mit
- Created: 2015-08-03T20:24:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-09-18T12:10:09.000Z (over 4 years ago)
- Last Synced: 2024-12-20T11:15:36.336Z (7 days ago)
- Language: Ruby
- Homepage:
- Size: 25.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Diffing
[![Build Status](https://travis-ci.org/denis-churbanov/Diffing.svg?branch=master)](https://travis-ci.org/denis-churbanov/Diffing)
## Installation
```
sudo gem install diffing
```## Usage
```ruby
require 'diffing'from = "Hello! I am string for diffing test"
to = "Hi! I am two string for diffing"
```#### By chars
```ruby
diff = Diffing.by_chars( from, to )diff.as_ascii
# => H{`ello`>>`i`}! I am{+` two`} string for diffing{-` test`}
diff.as_html
# => Helloi! I am two string for diffingtest
```#### By words
```ruby
diff = Diffing.by_words( from, to )diff.as_ascii
# => {`Hello!`>>`Hi!`} I am{+` two`} string for diffing{-` test`}
diff.as_html
# =>Hello!Hi! I am two string for diffingtest
```#### By lines
```ruby
diff = Diffing.by_lines( from, to )diff.as_ascii
# => {`Hello! I am string for diffing test`>>`Hi! I am two string for diffing`}
diff.as_html
# =>Hello! I am string for diffing testHi! I am two string for diffing
```## Custom format
```ruby
module CustomFormat
class << selfdef source( value )
value
enddef insert( value )
"(++#{ value })"
enddef remove( value )
"(--#{ value })"
enddef change( from, to )
"(#{ from } => #{ to })"
endend
endDiffing.by_chars( from, to ).format( CustomFormat )
# => H(ello => i)! I am(++ two) string for diffing(-- test)
Diffing.by_words( from, to ).format( CustomFormat )
# => (Hello! => Hi!) I am(++ two) string for diffing(-- test)
Diffing.by_lines( from, to ).format( CustomFormat )
# => (Hello! I am string for diffing test => Hi! I am two string for diffing)```
## Custom use separated parts
```ruby
Diffing.by_words( from, to ).parts.map { |part|
result = ''
result << "" if part.source?
result << "" if part.insert?
result << "" if part.remove?
result
}.join
# =>
```## Custom pattern of parts
```ruby
Diffing::Diff.new( from, to, /.{,3}\s?/ ).as_ascii
# => {`Hello! `>>`Hi! `}I a{`m string `>>`m two string `}for diffin{`g test`>>`g`}
```## Copyright
Copyright © 2015 Denis Churbanov