File: README.rdoc [diff-lcs-1.2.4 Documentation]

### Home Classes Methods

### Files

- Manifest.txt
- README.rdoc
- COPYING.txt
- artistic.txt

### Class Index

Quicksearch

- Diff
- Diff::LCS
- Diff::LCS::BalancedCallbacks
- Diff::LCS::Block
- Diff::LCS::Change
- Diff::LCS::ContextChange
- Diff::LCS::ContextDiffCallbacks
- Diff::LCS::DefaultCallbacks
- Diff::LCS::DiffCallbacks
- Diff::LCS::HTMLDiff
- Diff::LCS::HTMLDiff::Callbacks
- Diff::LCS::Hunk
- Diff::LCS::Ldiff
- Diff::LCS::SDiffCallbacks
- Diff::LCS::SequenceCallbacks
- Array
- String

No matching classes.

# Diff::LCS

home | diff-lcs.rubyforge.org/
code | github.com/halostatue/diff-lcs
bugs | github.com/halostatue/diff-lcs/issues
rdoc | rubydoc.info/github/halostatue/diff-lcs

## Description

Diff::LCS computes the difference between two Enumerable sequences using the McIlroy-Hunt longest common subsequence (LCS) algorithm. It includes utilities to create a simple HTML diff output format and a standard diff-like tool.

This is release 1.2.4, fixing a bug introduced after diff-lcs 1.1.3 that did not properly prune common sequences at the beginning of a comparison set. Thanks to Paul Kunysch for fixing this issue.

Coincident with the release of diff-lcs 1.2.3, we reported an issue with Rubinius in 1.9 mode (rubinius/rubinius#2268). We are happy to report that this issue has been resolved.

## Synopsis

Using this module is quite simple. By default, Diff::LCS does not extend objects with the Diff::LCS interface, but will be called as if it were a function:

    require 'diff/lcs'

    seq1 = %w(a b c e h j l m n p)
    seq2 = %w(b c d e f j k l m r s t)

    lcs = Diff::LCS.LCS(seq1, seq2)
    diffs = Diff::LCS.diff(seq1, seq2)
    sdiff = Diff::LCS.sdiff(seq1, seq2)
    seq = Diff::LCS.traverse_sequences(seq1, seq2, callback_obj)
    bal = Diff::LCS.traverse_balanced(seq1, seq2, callback_obj)
    seq2 == Diff::LCS.patch!(seq1, diffs)
    seq1 == Diff::LCS.unpatch!(seq2, diffs)
    seq2 == Diff::LCS.patch!(seq1, sdiff)
    seq1 == Diff::LCS.unpatch!(seq2, sdiff)

Objects can be extended with Diff::LCS:

    seq1.extend(Diff::LCS)
    lcs = seq1.lcs(seq2)
    diffs = seq1.diff(seq2)
    sdiff = seq1.sdiff(seq2)
    seq = seq1.traverse_sequences(seq2, callback_obj)
    bal = seq1.traverse_balanced(seq2, callback_obj)
    seq2 == seq1.patch!(diffs)
    seq1 == seq2.unpatch!(diffs)
    seq2 == seq1.patch!(sdiff)
    seq1 == seq2.unpatch!(sdiff)

By requiring 'diff/lcs/array' or 'diff/lcs/string', Array or String will be extended for use this way.

Note that Diff::LCS requires a sequenced enumerable container, which means that the order of enumeration is both predictable and consistent for the same set of data. While it is theoretically possible to generate a diff for an unordered hash, it will only be meaningful if the enumeration of the hashes is consistent. In general, this will mean that containers that behave like String or Array will perform best.

## History

Diff::LCS is a port of Perl's Algorithm::Diff that uses the McIlroy-Hunt longest common subsequence (LCS) algorithm to compute intelligent differences between two sequenced enumerable containers. The implementation is based on Mario I. Wolczko's Smalltalk version 1.2 (1993) and Ned Konz's Perl version Algorithm::Diff 1.15.

This library is called Diff::LCS because of an early version of Algorithm::Diff which was restrictively licensed.

## Continuous Integration Status

## Contributing

I value any contribution to Diff::LCS you can provide: a bug report, a feature request, or code contributions.

Code contributions to Diff::LCS are especially <del>welcome</del>encouraged. Because Diff::LCS is a complex codebase, there are a few guidelines:

- Changes <strong>will not</strong> be accepted without tests.

- The test suite is written with RSpec.???

- Match my coding style.

- Use a thoughtfully-named topic branch that contains your change. Rebase your commits into logical chunks as necessary.

- Use quality commit messages.

- Do not change the version number; when your patch is accepted and a release is made, the version will be updated at that point.

- Submit a GitHub pull request with your changes.

- New features require new documentation.

### Test Dependencies

To run the test suite, you will need to install the development dependencies for Diff::LCS. If you have Bundler, you can accomplish this easily:

    $ bundle install

Diff::LCS uses Ryan Davis???s excellent Hoe to manage the release process, and it adds a number of rake tasks. You will mostly be interested in:

    $ rake

which runs the tests the same way that:

    $ rake spec
    $ rake test
    $ rake travis

will do.

### Workflow

Here's the most direct way to get your work merged into the project:

- Fork the project.

- Clone down your fork (+git clone git://github.com/<username>/diff-lcs.git+).

- Create a topic branch to contain your change (+git checkout -b my_awesome_feature+).

- Hack away, add tests. Not necessarily in that order.

- Make sure everything still passes by running `rake`.

- If necessary, rebase your commits into logical chunks, without errors.

- Push the branch up (+git push origin my_awesome_feature+).

- Create a pull request against halostatue/diff-lcs and describe what your change does and the why you think it should be merged.

### Contributors

- Austin Ziegler created Diff::LCS.

Thanks to everyone else who has contributed to Diff::LCS:

- Kenichi Kamiya

- Michael Granger

- V??t Ondruch

- Jon Rowe

## License

This software is available under three licenses: the GNU GPL version 2 (or at your option, a later version), the Perl Artistic license, or the MIT license. Note that my preference for licensing is the MIT license, but Algorithm::Diff was dually originally licensed with the Perl Artistic and the GNU GPL ("the same terms as Perl itself") and given that the Ruby implementation originally hewed pretty closely to the Perl version, I must maintain the additional licensing terms.

- Copyright 2004???2013 Austin Ziegler.

- Adapted from Algorithm::Diff (Perl) by Ned Konz and a Smalltalk version by Mario I. Wolczko.

### MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

### Perl Artistic License (version 2)

See the file docs/artistic.txt in the main distribution.

### GNU GPL version 2

See the file docs/COPYING.txt in the main distribution.

[Validate]

Generated with the Darkfish Rdoc Generator 2.