matrix-ext 0.1.9

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.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+
data/.rvmrc ADDED
@@ -0,0 +1,4 @@
1
+ rvm use 1.9.3
2
+ #rvm use 1.9.2
3
+ rvm gemset create matrix-ext
4
+ rvm gemset use matrix-ext
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in matrix-ext.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Daniel J Nishimura
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.
@@ -0,0 +1,61 @@
1
+ # Matrix Extension
2
+
3
+
4
+ ## Overview
5
+
6
+ Extension methods for the Matrix class. WIP.
7
+
8
+ ### Installation
9
+ gem install matrix-ext
10
+
11
+ ### Usage
12
+ require 'matrix-ext'
13
+
14
+
15
+ ## Example
16
+ matrix = Matrix.build(4, 5) {0}
17
+ => Matrix[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
18
+ matrix.flatten
19
+ => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
20
+ matrix.column_size
21
+ => 5
22
+
23
+
24
+ ## Extension Methods
25
+
26
+ #### def column_size
27
+
28
+ Matrix has row_size, but surprisingly no column_size. I've added it here :)
29
+
30
+ #### def flatten
31
+
32
+ Returns the flatten matrix as an Array
33
+
34
+ #### More methods to come
35
+
36
+ ## Known Issues
37
+
38
+ Tested only against MRI 1.9.2 and 1.9.3
39
+
40
+
41
+ ## MIT License
42
+ Copyright (c) 2012 Daniel J Nishimura
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ "Software"), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
58
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
59
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
60
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
61
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ require "matrix-ext/version"
2
+ require "matrix-ext/methods"
3
+ require "matrix"
4
+
5
+ module MatrixExt
6
+ Matrix.class_eval do
7
+ include MatrixExt::Methods
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module MatrixExt::Methods
2
+ def column_size
3
+ return @rows[0].size if @rows.size > 0
4
+ 0
5
+ end
6
+
7
+ def flatten
8
+ Array.new(row_size) {|i|
9
+ row(i).to_a
10
+ }.reduce(:concat)
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ module MatrixExt
2
+ VERSION = "0.1.9"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "matrix-ext/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "matrix-ext"
7
+ s.version = MatrixExt::VERSION
8
+ s.authors = ["Daniel Nishimura"]
9
+ s.email = ["dnishimura@gmail.com"]
10
+ s.homepage = "http://github.com/dnishimura/matrix-ext"
11
+ s.summary = %q{Extension methods for the Matrix class}
12
+ s.description = %q{Adds useful methods to the Matrix class}
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_development_dependency "rspec", '~> 2.8.0'
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Matrix do
4
+ before(:all) do
5
+ @matrix = Matrix.build(3, 4) {|r,c| r*4 + c}
6
+ end
7
+
8
+ it "should flatten" do
9
+ @matrix.respond_to?(:flatten).should be_true
10
+ matrix_flat = @matrix.flatten
11
+ matrix_flat.size.should eq(12)
12
+ matrix_flat.should eq([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
13
+ end
14
+
15
+ it "should have column_size" do
16
+ @matrix.respond_to?(:column_size).should be_true
17
+ @matrix.column_size.should eq(4)
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'matrix-ext' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matrix-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Nishimura
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70206634994540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70206634994540
25
+ description: Adds useful methods to the Matrix class
26
+ email:
27
+ - dnishimura@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .rspec
34
+ - .rvmrc
35
+ - Gemfile
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/matrix-ext.rb
40
+ - lib/matrix-ext/methods.rb
41
+ - lib/matrix-ext/version.rb
42
+ - matrix-ext.gemspec
43
+ - spec/methods_spec.rb
44
+ - spec/spec_helper.rb
45
+ homepage: http://github.com/dnishimura/matrix-ext
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.6
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Extension methods for the Matrix class
69
+ test_files:
70
+ - spec/methods_spec.rb
71
+ - spec/spec_helper.rb