keybreak 0.1.0 → 0.1.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 +8 -8
- data/README.md +3 -0
- data/keybreak.gemspec +2 -0
- data/lib/keybreak/controller.rb +17 -17
- data/lib/keybreak/version.rb +3 -3
- data/lib/keybreak.rb +5 -5
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NzllZjEwM2Q1ODQzN2JkN2FkZGZmMjU3ZTUzM2ViMzY5NWVmN2FiNg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NDM4YWQyZDM3NDgyMDlkM2NlMWE4NGM0NGQzNWM2ZDg5YWJkNDIwZA==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
ZWYyNDMyMDU3ODA1ZDdmNzk2ZjY1NTZkZTUxMjk3Njg4NGNjYWFjYjU1ZmNi
|
|
10
|
+
NTgyNDMxM2U5NGYwZGZkNmE2NTFkMjNlNWEyYWYwOWYxNjMwMGVhNDhmMDlh
|
|
11
|
+
YjZiNzcyOTQwMTBjYTc5NjJkYjBiOGQwZTM4NmYyZWI0ODNhZWE=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
ODM0ODkwNjk5MGIxNzMyMmU5ZWZhOWM0Mzc0N2QwOGZmZjkwZTExZmJkODRh
|
|
14
|
+
ZDViZTI4OGRjMmY0YmJiZTBkYTA1M2Q2ZTVjZDUxZDE1MTk1OGRiYTU4MmRm
|
|
15
|
+
NDJjZTBkMzRlNGNkNmRlYmQzNjU2MjBhZjY1Y2U1ODY3OGIxNGQ=
|
data/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Keybreak is a utility module for Key break processing in Ruby.
|
|
|
8
8
|
|
|
9
9
|
The "key break processing" means, assuming a sorted sequence of column based records which can be grouped by a column,
|
|
10
10
|
doing the same process for each group.
|
|
11
|
+
|
|
11
12
|
The column used for the grouping is a "key".
|
|
12
13
|
In processing the record sequence, when the key's value in a record changes from the previous record,
|
|
13
14
|
it is called "key break".
|
|
@@ -160,6 +161,7 @@ e:8
|
|
|
160
161
|
### Print last values for each key
|
|
161
162
|
|
|
162
163
|
Borrows DATA from above example.
|
|
164
|
+
|
|
163
165
|
Register a keyend handler which prints the given key and value.
|
|
164
166
|
|
|
165
167
|
```ruby
|
|
@@ -215,6 +217,7 @@ e:17
|
|
|
215
217
|
### Print sum of values for each key and sub key
|
|
216
218
|
|
|
217
219
|
Nest Keybreak.execute_with_controller.
|
|
220
|
+
|
|
218
221
|
Give sub key handlers a set of primary key and sub key (an array for instance)
|
|
219
222
|
so that a primary key break is also detected as a sub key break.
|
|
220
223
|
|
data/keybreak.gemspec
CHANGED
data/lib/keybreak/controller.rb
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
module Keybreak
|
|
4
4
|
|
|
5
|
-
# Controller of
|
|
5
|
+
# Controller of key break processing
|
|
6
6
|
class Controller
|
|
7
7
|
|
|
8
|
-
#
|
|
8
|
+
# Generates an instance.
|
|
9
9
|
def initialize()
|
|
10
10
|
clear
|
|
11
11
|
@handlers = {}
|
|
@@ -14,8 +14,8 @@ module Keybreak
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
# Registers the given block as a
|
|
18
|
-
# Valid
|
|
17
|
+
# Registers the given block as a key break event handler.
|
|
18
|
+
# Valid events are:
|
|
19
19
|
# :keystart
|
|
20
20
|
# :keyend
|
|
21
21
|
def on(event, &block)
|
|
@@ -23,11 +23,11 @@ module Keybreak
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
# Detects
|
|
27
|
-
# When a new key comes,
|
|
28
|
-
#
|
|
29
|
-
# For the first key feed, does not call the keyend handler
|
|
30
|
-
# Use flush() to call the keyend handler for the last fed key
|
|
26
|
+
# Detects a key break and calls the registered handlers.
|
|
27
|
+
# When a new key comes, calls the :keyend handler with the last key and value,
|
|
28
|
+
# then call the :keystart handler with the new key and value.
|
|
29
|
+
# For the first key feed, does not call the :keyend handler.
|
|
30
|
+
# Use flush() to call the :keyend handler for the last fed key.
|
|
31
31
|
def feed(key, *values)
|
|
32
32
|
if @is_fed
|
|
33
33
|
if key != @key
|
|
@@ -45,17 +45,17 @@ module Keybreak
|
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
# Clears internal data to the status before key feed starts
|
|
48
|
+
# Clears internal data to the status before key feed starts.
|
|
49
49
|
def clear()
|
|
50
50
|
@is_fed = false
|
|
51
51
|
@values = []
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
# Calls the keyend handler once with the last fed key and value,
|
|
56
|
-
#
|
|
57
|
-
# Place this method after the last feed() to complete
|
|
58
|
-
# Does nothing when no key has been fed
|
|
55
|
+
# Calls the :keyend handler once with the last fed key and value,
|
|
56
|
+
# then clears internal data to the status before key feed starts.
|
|
57
|
+
# Place this method after the last feed() to complete key break process.
|
|
58
|
+
# Does nothing when no key has been fed.
|
|
59
59
|
def flush()
|
|
60
60
|
if @is_fed
|
|
61
61
|
@handlers[:keyend].call(@key, *@values)
|
|
@@ -65,9 +65,9 @@ module Keybreak
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
# Executes the given block and calls flush() finally
|
|
69
|
-
# Place feed() within the block so that the
|
|
70
|
-
#
|
|
68
|
+
# Executes the given block and calls flush() finally.
|
|
69
|
+
# Place feed() within the block so that the key break handlers are
|
|
70
|
+
# called for all keys including the last key.
|
|
71
71
|
def execute(&block)
|
|
72
72
|
instance_eval(&block)
|
|
73
73
|
self.flush
|
data/lib/keybreak/version.rb
CHANGED
data/lib/keybreak.rb
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
require "keybreak/version"
|
|
3
3
|
require "keybreak/controller"
|
|
4
4
|
|
|
5
|
-
# Utilities for
|
|
5
|
+
# Utilities for key break (control-break) processing
|
|
6
6
|
module Keybreak
|
|
7
7
|
|
|
8
|
-
# The block which does nothing
|
|
8
|
+
# The block which does nothing.
|
|
9
9
|
DO_NOTHING = Proc.new {}
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
# Executes the given block with a Controller instance
|
|
13
|
-
# Within the block, register your
|
|
14
|
-
# Then the handlers will be called for all keys including the last key
|
|
12
|
+
# Executes the given block with a Controller instance.
|
|
13
|
+
# Within the block, register your key break handlers and feed keys from your data.
|
|
14
|
+
# Then the handlers will be called for all keys including the last key.
|
|
15
15
|
def execute_with_controller(&block)
|
|
16
16
|
Controller.new.execute(&block)
|
|
17
17
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: keybreak
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- hashimoton
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-01-
|
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
87
87
|
requirements:
|
|
88
88
|
- - ! '>='
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
|
-
version:
|
|
90
|
+
version: 1.9.3
|
|
91
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
93
|
- - ! '>='
|
|
@@ -100,3 +100,4 @@ signing_key:
|
|
|
100
100
|
specification_version: 4
|
|
101
101
|
summary: Keybreak is a utility module for key break processing in Ruby.
|
|
102
102
|
test_files: []
|
|
103
|
+
has_rdoc:
|