rbsed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "riot", ">= 0"
5
+ gem "bundler", "~> 1.0.0"
6
+ end
7
+
8
+ # Specify your gem's dependencies in rbsed.gemspec
9
+ gemspec
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ ## simple text formatting
2
+
3
+ Usage:
4
+
5
+ ```ruby
6
+ "Foobar".sed('s/o/p/') # => Fpobar
7
+ "Foobar".sed('s/O/p') # => Foobar
8
+ "Foobar".sed('s/O/p/i') # => Fpobar
9
+ "Foobar".sed('s/o/p/g') # => Fppbar
10
+ "Foobar".sed('s/O/p/ig') # => Fppbar
11
+ ```
12
+
13
+ ## License
14
+
15
+ Copyright (c) 2011, Nick Markwell <nick@duckinator.net>
16
+
17
+ Permission to use, copy, modify, and/or distribute this software for any
18
+ purpose with or without fee is hereby granted, provided that the above
19
+ copyright notice and this permission notice appear in all copies.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+
6
+ desc "Run all tests"
7
+ task :test do
8
+ Rake::TestTask.new do |t|
9
+ t.libs << "test"
10
+ t.pattern = "test/**/*_test.rb"
11
+ t.verbose = false
12
+ end
13
+ end
14
+
15
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module RBSed
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rbsed.rb ADDED
@@ -0,0 +1,38 @@
1
+ $: << File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
2
+
3
+ class String
4
+
5
+ def sed(str)
6
+ match = nil
7
+ flags = []
8
+ options = 0
9
+ parts = str.split('/')
10
+
11
+ raise "Invalid sed command" if parts.length < 3
12
+
13
+ if parts.length > 3
14
+ flags = parts[3].split('')
15
+ options |= Regexp::IGNORECASE if flags.include?('i')
16
+ options |= Regexp::EXTENDED if flags.include?('x')
17
+ end
18
+
19
+ options = nil if options.zero?
20
+
21
+ case parts[0]
22
+ when 's'
23
+ match = Regexp.new(parts[1], options)
24
+ #when 'y'
25
+ # ???
26
+ else
27
+ raise "Invalid sed command"
28
+ end
29
+
30
+ if flags.include?('g')
31
+ self.gsub!(match) { parts[2] }
32
+ else
33
+ self.sub! (match) { parts[2] }
34
+ end
35
+
36
+ self
37
+ end
38
+ end
data/rbsed.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rbsed/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rbsed"
7
+ s.version = RBSed::VERSION
8
+ s.authors = ["Nick Markwell"]
9
+ s.email = ["nick@duckinator.net"]
10
+ s.homepage = "https://github.com/duckinator/rbsed"
11
+ s.summary = %q{Provides str.sed('s/a/b/flags') and similar.}
12
+ s.description = s.summary
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'teststrap'
2
+
3
+ context 'RBSed - ' do
4
+ setup { }
5
+
6
+ context 'main' do
7
+ asserts("Foobar".sed('s/o/p' )) { "Fpobar" }
8
+ asserts("Foobar".sed('s/O/p' )) { "Foobar" }
9
+ asserts("Foobar".sed('s/o/p/' )) { "Fpobar" }
10
+ asserts("Foobar".sed('s/O/p/' )) { "Foobar" }
11
+ asserts("Foobar".sed('s/O/p/i' )) { "Fpobar" }
12
+ asserts("Foobar".sed('s/o/p/g' )) { "Fppbar" }
13
+ asserts("Foobar".sed('s/O/p/ig')) { "Fppbar" }
14
+ asserts("Foobar".sed('s/O/p/g' )) { "Foobar" }
15
+ end
16
+ end
data/test/teststrap.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+ require 'riot'
10
+ require 'rbsed'
11
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbsed
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Nick Markwell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-17 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: Provides str.sed('s/a/b/flags') and similar.
17
+ email:
18
+ - nick@duckinator.net
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .gitignore
27
+ - Gemfile
28
+ - README.md
29
+ - Rakefile
30
+ - lib/rbsed.rb
31
+ - lib/rbsed/version.rb
32
+ - rbsed.gemspec
33
+ - test/rbsed_test.rb
34
+ - test/teststrap.rb
35
+ homepage: https://github.com/duckinator/rbsed
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.5
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Provides str.sed('s/a/b/flags') and similar.
62
+ test_files:
63
+ - test/rbsed_test.rb
64
+ - test/teststrap.rb