arrayie 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +5 -0
- data/LICENCE +15 -0
- data/README.md +65 -0
- data/Rakefile +8 -0
- data/arrayie.gemspec +29 -0
- data/lib/arrayie.rb +22 -0
- data/lib/arrayie/tools.rb +37 -0
- data/lib/arrayie/version.rb +20 -0
- data/test/lib/arrayie/tools_test.rb +73 -0
- data/test/test_helper.rb +19 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2219b973f18c45cfda8ea686cc6fcd182bd34cf8
|
4
|
+
data.tar.gz: 33a7d072d339e04ee3b3e8bf2797245f06092865
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6924996bc8df470d28e8d7f234a2339b1e1cc2613276a2541f52aefad5e1c3d060123247de19cb6a42069960a8cca802faf45f14690f7f867148a38709bd15f5
|
7
|
+
data.tar.gz: 1d42af357d7584ad24bb9d0c1fa80ac50c136eb90c7f2a23e6c6f51d7d2164a312041c93a0d3cd8399098d312fc9ca5977af1b396193f3435acae2c5f907460d
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENCE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Arrayie is a library which contains tools for working with Array in Ruby.
|
2
|
+
Copyright (C) 2017 Hamed Ramezanian Nik
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Arrayie
|
2
|
+
|
3
|
+
Arrayie is a library which contains tools for working with Array in Ruby.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
Ruby >= 2.4
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
### RubyGems
|
11
|
+
|
12
|
+
Add this to the Gemfile:
|
13
|
+
|
14
|
+
gem 'arrayie'
|
15
|
+
|
16
|
+
or install it directly:
|
17
|
+
|
18
|
+
gem install arrayie
|
19
|
+
|
20
|
+
### Install from Git
|
21
|
+
|
22
|
+
Add the following in the Gemfile:
|
23
|
+
|
24
|
+
gem 'arrayie', :git => 'https://github.com/iCEAGE/arrayie.git'
|
25
|
+
|
26
|
+
|
27
|
+
## Getting Started
|
28
|
+
|
29
|
+
Please follow the [installation](#installation) procedure and then run the following code:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Load the gem
|
33
|
+
require 'arrayie'
|
34
|
+
|
35
|
+
array_utils = Arrayie::Tools.new
|
36
|
+
|
37
|
+
input_array = [[1, 2, [3]], 4]
|
38
|
+
|
39
|
+
flattened_array = array_utils.flatten(input_array)
|
40
|
+
|
41
|
+
puts flattened_array
|
42
|
+
```
|
43
|
+
|
44
|
+
## Tests
|
45
|
+
To run the tests:
|
46
|
+
````
|
47
|
+
bundle exec rake
|
48
|
+
````
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
Copyright (C) 2017 Hamed Ramezanian Nik
|
53
|
+
|
54
|
+
This program is free software: you can redistribute it and/or modify
|
55
|
+
it under the terms of the GNU Lesser General Public License as published by
|
56
|
+
the Free Software Foundation, either version 3 of the License, or
|
57
|
+
(at your option) any later version.
|
58
|
+
|
59
|
+
This program is distributed in the hope that it will be useful,
|
60
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
61
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
62
|
+
GNU Lesser General Public License for more details.
|
63
|
+
|
64
|
+
You should have received a copy of the GNU Lesser General Public License
|
65
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
data/arrayie.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require_relative 'lib/arrayie'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'arrayie'
|
7
|
+
gem.version = Arrayie::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.authors = ['Hamed Ramezanian Nik']
|
10
|
+
gem.email = ['hamed.r.nik@gmail.com']
|
11
|
+
gem.summary = 'Arrayie is a library which contains tools for working '\
|
12
|
+
'with Array in Ruby.'
|
13
|
+
gem.description = 'Arrayie is a library which contains tools for working '\
|
14
|
+
'with Array in Ruby.'
|
15
|
+
gem.homepage = 'https://github.com/iCEAGE/arrayie'
|
16
|
+
gem.license = 'LGPL-3.0'
|
17
|
+
|
18
|
+
gem.files = `git ls-files | grep -Ev '^(myapp|examples)'`.split("\n")
|
19
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
21
|
+
File.basename(f)
|
22
|
+
end
|
23
|
+
gem.require_paths = ['lib']
|
24
|
+
|
25
|
+
gem.required_ruby_version = '>= 2.4'
|
26
|
+
|
27
|
+
gem.add_development_dependency 'rake', '~> 12.0'
|
28
|
+
gem.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.1'
|
29
|
+
end
|
data/lib/arrayie.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Arrayie is a library which contains tools for working with Array in Ruby.
|
2
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require_relative 'arrayie/version'
|
18
|
+
require_relative 'arrayie/tools'
|
19
|
+
|
20
|
+
# This module contains functionality for transforming an Array type
|
21
|
+
module Arrayie
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Arrayie is a library which contains tools for working with Array in Ruby.
|
2
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
module Arrayie
|
18
|
+
# This class contains tools for working with Array type
|
19
|
+
class Tools
|
20
|
+
# Flattens a Array type
|
21
|
+
#
|
22
|
+
# @param [Array] input_array An array
|
23
|
+
# @return [Array] flattened input array
|
24
|
+
# @raise [ArgumentError] if the input array is not an Array type
|
25
|
+
def flatten(input_array)
|
26
|
+
unless input_array.is_a?(Array)
|
27
|
+
raise ArgumentError, 'Accepted input should be an Array type.'
|
28
|
+
end
|
29
|
+
|
30
|
+
input_array.inject([]) do |output_array, item|
|
31
|
+
output_array += item.is_a?(Array) ? flatten(item) : [item]
|
32
|
+
|
33
|
+
output_array
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Arrayie is a library which contains tools for working with Array in Ruby.
|
2
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
# Library version
|
18
|
+
module Arrayie
|
19
|
+
VERSION = '0.0.1'.freeze unless defined? Arrayie::VERSION
|
20
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Arrayie is a library which contains tools for working with Array in Ruby.
|
2
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require_relative '../../test_helper'
|
18
|
+
|
19
|
+
class ToolsTest < MiniTest::Test
|
20
|
+
def setup
|
21
|
+
@arrayie_tools = Arrayie::Tools.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_flat_an_array_of_integers
|
25
|
+
input_array = [[1, 2, [3]], 4]
|
26
|
+
flattened_array = @arrayie_tools.flatten(input_array)
|
27
|
+
assert_equal flattened_array, [1, 2, 3, 4]
|
28
|
+
assert_equal input_array, [[1, 2, [3]], 4]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_flat_an_array_of_integers_twice
|
32
|
+
input_array = [[1, 2, [3]], 4]
|
33
|
+
@arrayie_tools.flatten(input_array)
|
34
|
+
flattened_array = @arrayie_tools.flatten(input_array)
|
35
|
+
assert_equal flattened_array, [1, 2, 3, 4]
|
36
|
+
assert_equal input_array, [[1, 2, [3]], 4]
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_flat_an_array_of_strings
|
40
|
+
input_array = ['a', ['b', ['c', []]], 'd']
|
41
|
+
flattened_array = @arrayie_tools.flatten(input_array)
|
42
|
+
assert_equal flattened_array, %w[a b c d]
|
43
|
+
assert_equal input_array, ['a', ['b', ['c', []]], 'd']
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_flat_an_empty_array
|
47
|
+
input_array = []
|
48
|
+
flattened_array = @arrayie_tools.flatten(input_array)
|
49
|
+
assert_equal flattened_array, []
|
50
|
+
assert_equal input_array, []
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_flat_nested_empty_array
|
54
|
+
input_array = [[], [[]], []]
|
55
|
+
flattened_array = @arrayie_tools.flatten(input_array)
|
56
|
+
assert_equal flattened_array, []
|
57
|
+
assert_equal input_array, [[], [[]], []]
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_flat_an_array_with_nil
|
61
|
+
input_array = [[1, 2], nil, [[1], nil], ['string', nil, []]]
|
62
|
+
flattened_array = @arrayie_tools.flatten(input_array)
|
63
|
+
assert_equal flattened_array, [1, 2, nil, 1, nil, 'string', nil]
|
64
|
+
assert_equal input_array, [[1, 2], nil, [[1], nil], ['string', nil, []]]
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_flat_non_array
|
68
|
+
input_array = 'This is wrong!'
|
69
|
+
assert_raises ArgumentError do
|
70
|
+
@arrayie_tools.flatten(input_array)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Arrayie is a library which contains tools for working with Array in Ruby.
|
2
|
+
# Copyright (C) 2017 Hamed Ramezanian Nik
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require_relative '../lib/arrayie'
|
18
|
+
|
19
|
+
require 'minitest/autorun'
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arrayie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hamed Ramezanian Nik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.10'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 5.10.1
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.10'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 5.10.1
|
47
|
+
description: Arrayie is a library which contains tools for working with Array in Ruby.
|
48
|
+
email:
|
49
|
+
- hamed.r.nik@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- ".gitignore"
|
55
|
+
- Gemfile
|
56
|
+
- LICENCE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- arrayie.gemspec
|
60
|
+
- lib/arrayie.rb
|
61
|
+
- lib/arrayie/tools.rb
|
62
|
+
- lib/arrayie/version.rb
|
63
|
+
- test/lib/arrayie/tools_test.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
homepage: https://github.com/iCEAGE/arrayie
|
66
|
+
licenses:
|
67
|
+
- LGPL-3.0
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.4'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.6.12
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Arrayie is a library which contains tools for working with Array in Ruby.
|
89
|
+
test_files:
|
90
|
+
- test/lib/arrayie/tools_test.rb
|
91
|
+
- test/test_helper.rb
|