Class: Tb::NumericReader
- Inherits:
-
Object
- Object
- Tb::NumericReader
- Includes:
- EnumerableWithEach
- Defined in:
- lib/tb/numericreader.rb
Overview
lib/tb/numericreaderm.rb - reader mixin for table without header
Copyright (C) 2014 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:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- 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.
- 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.
Direct Known Subclasses
Instance Method Summary collapse
- #get_hash ⇒ Object
- #get_named_header ⇒ Object
- #header_and_each(header_proc) ⇒ Object
- #header_known? ⇒ Boolean
-
#initialize(get_array) ⇒ NumericReader
constructor
A new instance of NumericReader.
Methods included from EnumerableWithEach
Methods included from Enumerable
#cat, #extsort_by, #natjoin2, #natjoin2_outer, #newfield, #to_fileenumerator, #with_cumulative_header, #with_header, #write_to_csv, #write_to_json, #write_to_ltsv, #write_to_pnm, #write_to_tsv, #write_with
Constructor Details
#initialize(get_array) ⇒ NumericReader
Returns a new instance of NumericReader.
34 35 36 |
# File 'lib/tb/numericreader.rb', line 34 def initialize(get_array) @get_array = get_array end |
Instance Method Details
#get_hash ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tb/numericreader.rb', line 46 def get_hash ary = @get_array.call if !ary return nil end hash = {} ary.each_with_index {|v, i| field = (i+1).to_s hash[field] = v } hash end |
#get_named_header ⇒ Object
42 43 44 |
# File 'lib/tb/numericreader.rb', line 42 def get_named_header [] end |
#header_and_each(header_proc) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/tb/numericreader.rb', line 59 def header_and_each(header_proc) header_proc.call(get_named_header) if header_proc while hash = get_hash yield hash end nil end |
#header_known? ⇒ Boolean
38 39 40 |
# File 'lib/tb/numericreader.rb', line 38 def header_known? false end |