Class: Tb::Zipper
- Inherits:
-
Object
- Object
- Tb::Zipper
- Defined in:
- lib/tb/zipper.rb
Overview
Copyright © 2012 Tanaka Akira <[email protected]>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Instance Method Summary collapse
- #aggregate(ary) ⇒ Object
- #call(ary1, ary2) ⇒ Object
-
#initialize(ops) ⇒ Zipper
constructor
A new instance of Zipper.
- #start(ary) ⇒ Object
Constructor Details
#initialize(ops) ⇒ Zipper
Returns a new instance of Zipper.
30 31 32 |
# File 'lib/tb/zipper.rb', line 30 def initialize(ops) @ops = ops end |
Instance Method Details
#aggregate(ary) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/tb/zipper.rb', line 52 def aggregate(ary) if ary.length != @ops.length raise ArgumentError, "expect an array which lengths are #{@ops.length}" end @ops.map.with_index {|op, i| op.aggregate(ary[i]) } end |
#call(ary1, ary2) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/tb/zipper.rb', line 43 def call(ary1, ary2) if ary1.length != @ops.length || ary2.length != @ops.length raise ArgumentError, "expect an array of arrays which lengths are #{@ops.length}" end @ops.zip(ary1, ary2).map {|op, v1, v2| op.call(v1, v2) } end |
#start(ary) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/tb/zipper.rb', line 34 def start(ary) if ary.length != @ops.length raise ArgumentError, "expect an array which lengths are #{@ops.length}" end @ops.map.with_index {|op, i| op.start(ary[i]) } end |