# LineContaining [![Gem Version](https://badge.fury.io/rb/line_containing.svg)](https://badge.fury.io/rb/line_containing) [![Build Status](https://travis-ci.org/jhsu802701/line_containing.svg?branch=version_0_0_1)](https://travis-ci.org/jhsu802701/line_containing) [![Dependency Status](https://gemnasium.com/badges/github.com/jhsu802701/line_containing.svg)](https://gemnasium.com/github.com/jhsu802701/line_containing) [![Code Climate](https://codeclimate.com/github/jhsu802701/line_containing/badges/gpa.svg)](https://codeclimate.com/github/jhsu802701/line_containing) [![Test Coverage](https://codeclimate.com/github/jhsu802701/line_containing/badges/coverage.svg)](https://codeclimate.com/github/jhsu802701/line_containing/coverage) ## What This Gem Does The LineContaing gem is changing the contents of a file based on the content in a line. Some examples: * Look for a line containing specific content, and add a new line before it. ``` one two three four five six ten eleven twelve thirteen fourteen fifteen ``` Add the line "seven eight nine" before the line containing "ten". ``` one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen ``` * Look for a line containing specific content, and add a new line after it. ``` one two three four five six ten eleven twelve thirteen fourteen fifteen ``` Add the line "seven eight nine" after the line containing "six" ``` one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen ``` * Look for a line containing specific content, and add a new line in place of it. ``` one two three four five six sixteen seventeen eighteen ten eleven twelve thirteen fourteen fifteen ``` Add the line "seven eight nine" in place of the line containing "seventeen". ``` one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen ``` * Look for a line containing specific content, and delete this line. ``` one two three four five six seven eight nine sixteen seventeen eighteen ten eleven twelve thirteen fourteen fifteen ``` Delete the line containing "seventeen". ``` one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen ``` * Look for lines containing specific content, and delete everything in between. ``` one two three a b c d e f g h i four five six ``` Delete the lines between "two" and "five". ``` one two three four five six ``` * Look for lines containing specific content, delete them, and delete everything in between. ``` one two three a b c d e f g h i four five six ``` Delete the lines containing "two" and "five" plus everything in between. ``` one two three four five six ``` ## Installation Add this line to your application's Gemfile: ```ruby gem 'line_containing' ``` And then execute: $ bundle Or install it yourself as: $ gem install line_containing ## Usage #### Look for a line containing specific content, and add a new line before it. EXAMPLE: In the file "file1.txt", look for the line containing "ten", and add the line "seven eight nine" before it. ``` LineContaining.add_before("ten", "seven eight nine", "file1.txt") ``` #### Look for a line containing specific content, and add a new line after it. EXAMPLE: In the file "file2.txt", look for the line containing "six", and add the line "seven eight nine" after it. ``` LineContaining.add_after("six", "seven eight nine", "file2.txt") ``` #### Look for a line containing specific content, and add a new line in place of it. EXAMPLE: In the file "file3.txt", look for the line containing "seventeen", and add the line "seven eight nine" in place of it. ``` LineContaining.replace("seventeen", "seven eight nine", "file3.txt") ``` #### Look for a line containing specific content, and delete this line. EXAMPLE: In the file "file4.txt", look for the line containing "seventeen", and delete it. ``` LineContaining.delete("seventeen", "file4.txt") ``` #### Look for lines containing specific content, and delete everything in between. EXAMPLE: In the file "file7.txt", look for the line containing "one" and the line containing "six", and delete everything in between. ``` LineContaining.delete_between('one', 'six', 'file7.txt') ``` #### Look for lines containing specific content. Delete these lines and everything in between. EXAMPLE: In the file "file8.txt", look for the line containing "a b" and the line containing "h i". Delete these lines and everything in between. ``` LineContaining.delete_between_plus('a b', 'h i', 'file8.txt') ``` ## Development ### Testing this gem Enter `sh gem_test.sh`. ### Running this gem in irb Enter `sh gem_console.sh`. ### Installing this gem Enter `sh gem_install.sh`. ## Contributing 1. Fork it ( https://github.com/[my-github-username]/line_containing/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request