rb_ext 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ gem "rcov", ">= 0"
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 icatcher.at
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = rb_ext
2
+
3
+ Adds a bunch of methods to Ruby's Core Library.
4
+
5
+ == Installation
6
+
7
+ gem install rb_ext
8
+
9
+ or simply add the dependency to the Gemfile of your application:
10
+
11
+ gem "rb_ext"
12
+
13
+ and then call bundle install on your console.
14
+
15
+ = Usage
16
+
17
+ == Array
18
+
19
+ === Array#split(_separator_)
20
+
21
+ Splits an array by _separator_ and returns an array holding
22
+ the splitted values in arrays. Works like String#split for arrays but
23
+ only on the first level of the array (for now).
24
+
25
+ Example:
26
+ a = %w(a b c - d e f g - h i j - k)
27
+ a.split("-") # => [[a, b, c], [d, e, f, g], [h, i, j] [k]]
28
+
29
+ a = ["a", "b", ["c", "d", "-", "e"], "-", "f"]
30
+ a.split("-") # => [["a", "b", ["c", "d", "-", "e"]], ["f"]]
31
+
32
+ === Array#n_up(_n_)
33
+
34
+ Computes each element of the array with _n_. Supports nested arrays.
35
+
36
+ Example:
37
+ a = ["a", "b", 1, "c", 2.5, ["d", 3], "e"]
38
+ a.n_up(2) # => ["aa", "bb", 2, "cc", 5.0, ["dd", 6], "ee"]
39
+
40
+ a3.n_up(3.5) # => ["aaa", "bbb", 3.5, "ccc", 8.75, ["ddd", 10.5], "eee"]
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2011 Robert Neumayr. See LICENSE.txt for
45
+ further details.
46
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "rb_ext"
16
+ gem.homepage = "http://github.com/icatcher-at/rb_ext"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Adds a bunch of methods to Ruby's Core Library}
19
+ gem.description = %Q{Adds a bunch of methods to Ruby's Core Library, like Array#split or Array#double}
20
+ gem.email = "kontakt@icatcher.at"
21
+ gem.authors = ["icatcher.at"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rb_ext #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,58 @@
1
+ module RbExt
2
+ module Array
3
+ # Splits an array by _separator_ and returns an array holding
4
+ # the splitted values in arrays. Works like String#split for arrays.
5
+ #
6
+ # -- TODO: modify to support nested arrays
7
+ #
8
+ #
9
+ # a = %w(a b c - d e f g - h i j - k)
10
+ # a.split("-") # => [[a, b, c], [d, e, f, g], [h, i, j] [k]]
11
+ #
12
+ # a = ["a", "b", ["c", "d", "-", "e"], "-", "f"]
13
+ # a.split("-") # => [["a", "b", ["c", "d", "-", "e"]], ["f"]]
14
+ def split(separator)
15
+ if self.count(separator) >= 1
16
+ sep_indices = []
17
+ result = []
18
+
19
+ self.each_with_index do |item, index|
20
+ sep_indices << index if item == separator
21
+ end
22
+ sep_indices << self.size
23
+
24
+ start = 0
25
+ sep_indices.each do |index|
26
+ result << self.slice(start..index-1)
27
+ start = index + 1
28
+ end
29
+
30
+ result
31
+ else
32
+ self
33
+ end
34
+ end
35
+
36
+
37
+ # Computes each element of the array with _n_
38
+ # and supports nested arrays.
39
+ #
40
+ # a = ["a", "b", 1, "c", 2.5, ["d", 3], "e"]
41
+ # a.n_up(2) # => ["aa", "bb", 2, "cc", 5.0, ["dd", 6], "ee"]
42
+ #
43
+ # a3.n_up(3.5) # => ["aaa", "bbb", 3.5, "ccc", 8.75, ["ddd", 10.5], "eee"]
44
+ def n_up(n)
45
+ result = []
46
+
47
+ self.map do |item|
48
+ if item.respond_to?(:n_up)
49
+ result << item.n_up(n)
50
+ else
51
+ result << item * n
52
+ end
53
+ end
54
+
55
+ result
56
+ end
57
+ end
58
+ end
data/lib/rb_ext.rb ADDED
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require "rb_ext/array"
4
+
5
+ Array.send :include, RbExt::Array
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'rb_ext'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class TestRbExtArray < Test::Unit::TestCase
4
+ def test_should_slice_array
5
+ a = %w(a b c - d e f - g)
6
+ assert_equal a.split("-"), [["a", "b", "c"], ["d", "e", "f"], ["g"]]
7
+
8
+ a = ["a", "-", "b", ["c", ["d", "-", "e"], "f"], "-", "g"]
9
+ assert_equal a.split("-"), [["a"], ["b", ["c", ["d", "-", "e"], "f"]], ["g"]]
10
+ end
11
+
12
+ def test_should_double_array
13
+ a = ["a", "b", 1, "c", 2.5]
14
+ assert_equal a.n_up(2), ["aa", "bb", 2, "cc", 5.0]
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_ext
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - icatcher.at
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-25 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 5
45
+ - 2
46
+ version: 1.5.2
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rcov
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ description: Adds a bunch of methods to Ruby's Core Library, like Array#split or Array#double
64
+ email: kontakt@icatcher.at
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ files:
73
+ - .document
74
+ - Gemfile
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ - Rakefile
78
+ - VERSION
79
+ - lib/rb_ext.rb
80
+ - lib/rb_ext/array.rb
81
+ - test/helper.rb
82
+ - test/test_rb_ext_array.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/icatcher-at/rb_ext
85
+ licenses:
86
+ - MIT
87
+ post_install_message:
88
+ rdoc_options: []
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 992278145
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.3.7
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Adds a bunch of methods to Ruby's Core Library
116
+ test_files:
117
+ - test/helper.rb
118
+ - test/test_rb_ext_array.rb