sorted_array 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO.md +1 -0
- data/lib/sorted_array.rb +1 -64
- data/lib/sorted_array/version.rb +1 -1
- data/sorted_array.gemspec +1 -1
- metadata +5 -5
data/TODO.md
CHANGED
data/lib/sorted_array.rb
CHANGED
@@ -1,71 +1,8 @@
|
|
1
1
|
require 'sorted_array/version'
|
2
2
|
require 'sorted_array/default_sorter'
|
3
|
+
require 'sorted_array/sorted_array'
|
3
4
|
|
4
5
|
# The gem/module provides a class SortedArray which keeps sorted
|
5
6
|
# with a given Sorter-class after adding new items.
|
6
7
|
module SortedArray
|
7
|
-
|
8
|
-
# A SortedArray takes a Sorter-object as a parameter.
|
9
|
-
# The array gets sorted after each push,<<,unsift.
|
10
|
-
# It defines marshal-methods and can be used with PStore
|
11
|
-
# @see DefaultSorter
|
12
|
-
class SortedArray < Array
|
13
|
-
|
14
|
-
# @params [Array] args the first argument is a Sorter-object
|
15
|
-
# @example
|
16
|
-
# my_array = SortedArray.new( DefaultSorter.new(:foo) )
|
17
|
-
# my_array << AnyClassWhichSupportsFoo.new(1)
|
18
|
-
# my_array << AnyClassWhichSupportsFoo.new(3)
|
19
|
-
# my_array << AnyClassWhichSupportsFoo.new(2)
|
20
|
-
# # my_array.map(&:foo) => 1,2,3
|
21
|
-
# @see DefaultSorter
|
22
|
-
# @see Array
|
23
|
-
def initialize *args
|
24
|
-
@sorter = args.shift
|
25
|
-
super
|
26
|
-
end
|
27
|
-
|
28
|
-
# @see Array
|
29
|
-
def push *other
|
30
|
-
super
|
31
|
-
@sorter.sort(self)
|
32
|
-
end
|
33
|
-
|
34
|
-
# @see Array
|
35
|
-
def unshift other
|
36
|
-
super
|
37
|
-
@sorter.sort(self)
|
38
|
-
end
|
39
|
-
|
40
|
-
# @see Array
|
41
|
-
def << other
|
42
|
-
push *other
|
43
|
-
@sorter.sort(self)
|
44
|
-
end
|
45
|
-
|
46
|
-
protected
|
47
|
-
|
48
|
-
# @return [Array] - Sorter-object or nil, [...values...]
|
49
|
-
def marshal_dump
|
50
|
-
[@sorter ? @sorter.marshal_dump : nil, to_a]
|
51
|
-
end
|
52
|
-
|
53
|
-
# Initialize sorter and read in data
|
54
|
-
# @param [Array] array - _sorter, [..entries..]
|
55
|
-
def marshal_load array
|
56
|
-
_sorter, _data = *array
|
57
|
-
if _sorter
|
58
|
-
initialize_sorter _sorter
|
59
|
-
push *_data if _data
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def initialize_sorter args
|
66
|
-
@sorter = args.shift.new *args
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
8
|
end
|
data/lib/sorted_array/version.rb
CHANGED
data/sorted_array.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = SortedArray::VERSION
|
9
9
|
spec.authors = ["Andi Altendorfer"]
|
10
10
|
spec.email = ["andi@iboard.cc"]
|
11
|
-
spec.description = %q{
|
11
|
+
spec.description = %q{Class SortedArray keeps sorted after push-actions using a Sorter-class. Implements marshal-functions thus it can be used in PStores.}
|
12
12
|
spec.summary = 'SortedArray.new { |a,b| a.foo <=> b.foo }'
|
13
13
|
spec.homepage = "https://github.com/iboard/sorted_array"
|
14
14
|
spec.license = "MIT"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorted_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -171,8 +171,8 @@ dependencies:
|
|
171
171
|
- - '>='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
|
-
description:
|
175
|
-
|
174
|
+
description: Class SortedArray keeps sorted after push-actions using a Sorter-class.
|
175
|
+
Implements marshal-functions thus it can be used in PStores.
|
176
176
|
email:
|
177
177
|
- andi@iboard.cc
|
178
178
|
executables: []
|
@@ -209,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
209
|
version: '0'
|
210
210
|
segments:
|
211
211
|
- 0
|
212
|
-
hash:
|
212
|
+
hash: 3780593145645614316
|
213
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
214
|
none: false
|
215
215
|
requirements:
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
segments:
|
220
220
|
- 0
|
221
|
-
hash:
|
221
|
+
hash: 3780593145645614316
|
222
222
|
requirements: []
|
223
223
|
rubyforge_project:
|
224
224
|
rubygems_version: 1.8.25
|