1
1
# lib/tb/basic.rb - basic fetures for table library
2
2
#
3
3
# Copyright (C) 2010-2012 Tanaka Akira <[email protected] >
4
- #
4
+ #
5
5
# Redistribution and use in source and binary forms, with or without
6
6
# modification, are permitted provided that the following conditions
7
7
# are met:
8
- #
8
+ #
9
9
# 1. Redistributions of source code must retain the above copyright
10
10
# notice, this list of conditions and the following disclaimer.
11
11
# 2. Redistributions in binary form must reproduce the above
15
15
# 3. The name of the author may not be used to endorse or promote
16
16
# products derived from this software without specific prior
17
17
# written permission.
18
- #
18
+ #
19
19
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -220,11 +220,11 @@ def define_field(field)
220
220
#
221
221
# returns true if the field specified by the argument is exist.
222
222
#
223
- # t = Tb.new %w[fruit color],
224
- # %w[apple red],
225
- # %w[banana yellow],
226
- # %w[orange orange]
227
- # pp t
223
+ # t = Tb.new %w[fruit color],
224
+ # %w[apple red],
225
+ # %w[banana yellow],
226
+ # %w[orange orange]
227
+ # pp t
228
228
# #=> #<Tb
229
229
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
230
230
# # {"_recordid"=>1, "fruit"=>"banana", "color"=>"yellow"}
@@ -323,7 +323,7 @@ def reorder_fields!(fields)
323
323
# # {"_recordid"=>1, "fruit"=>"banana", "color"=>"yellow"}
324
324
# # {"_recordid"=>2, "fruit"=>"orange", "color"=>"orange"}>
325
325
# p t.list_recordids #=> [0, 1, 2]
326
- #
326
+ #
327
327
def list_recordids
328
328
@tbl [ "_recordid" ] . compact
329
329
end
@@ -333,10 +333,10 @@ def list_recordids
333
333
#
334
334
# returns the number of records.
335
335
#
336
- # t = Tb.new %w[fruit],
337
- # %w[apple],
338
- # %w[banana],
339
- # %w[orange]
336
+ # t = Tb.new %w[fruit],
337
+ # %w[apple],
338
+ # %w[banana],
339
+ # %w[orange]
340
340
# pp t
341
341
# #=> #<Tb
342
342
# # {"_recordid"=>0, "fruit"=>"apple"}
@@ -360,10 +360,10 @@ def size
360
360
# p t0.empty?
361
361
# #=> true
362
362
#
363
- # t3 = Tb.new %w[fruit],
364
- # %w[apple],
365
- # %w[banana],
366
- # %w[orange]
363
+ # t3 = Tb.new %w[fruit],
364
+ # %w[apple],
365
+ # %w[banana],
366
+ # %w[orange]
367
367
# pp t3
368
368
# #=> #<Tb
369
369
# # {"_recordid"=>0, "fruit"=>"apple"}
@@ -514,7 +514,7 @@ def get_cell(recordid, field)
514
514
# t = Tb.new %w[fruit color],
515
515
# %w[apple red],
516
516
# %w[banana yellow],
517
- # %w[orange orange]
517
+ # %w[orange orange]
518
518
# pp t
519
519
# #=> #<Tb
520
520
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
@@ -531,7 +531,7 @@ def get_cell(recordid, field)
531
531
def delete_cell ( recordid , field )
532
532
recordid = check_recordid ( recordid )
533
533
field = check_field ( field )
534
- raise ArgumentError , "can not delete reserved field: #{ field . inspect } " if field . start_with? ( "_" )
534
+ raise ArgumentError , "can not delete reserved field: #{ field . inspect } " if field . start_with? ( "_" )
535
535
ary = @tbl [ field ]
536
536
index = @recordid2index [ recordid ]
537
537
old = ary [ index ]
@@ -703,7 +703,7 @@ def concat(*tables)
703
703
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
704
704
# # {"_recordid"=>1, "fruit"=>"banana", "color"=>"yellow"}
705
705
# # {"_recordid"=>2, "fruit"=>"orange", "color"=>"orange"}>
706
- # p t.update_record(1, {"color"=>"green"})
706
+ # p t.update_record(1, {"color"=>"green"})
707
707
# #=> nil
708
708
# pp t
709
709
# #=> #<Tb
@@ -761,7 +761,7 @@ def get_values(recordid, *fields)
761
761
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
762
762
# # {"_recordid"=>1, "fruit"=>"banana", "color"=>"yellow"}
763
763
# # {"_recordid"=>2, "fruit"=>"orange", "color"=>"orange"}>
764
- # p t.get_record(1)
764
+ # p t.get_record(1)
765
765
# #=> #<Tb::Record: "_recordid"=>1, "fruit"=>"banana", "color"=>"yellow">
766
766
#
767
767
def get_record ( recordid )
@@ -774,10 +774,10 @@ def get_record(recordid)
774
774
#
775
775
# iterates over the non-reserved field names of the table.
776
776
#
777
- # t = Tb.new %w[fruit color],
778
- # %w[apple red],
779
- # %w[banana yellow],
780
- # %w[orange orange]
777
+ # t = Tb.new %w[fruit color],
778
+ # %w[apple red],
779
+ # %w[banana yellow],
780
+ # %w[orange orange]
781
781
# pp t
782
782
# #=> #<Tb
783
783
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
@@ -800,10 +800,10 @@ def each_field
800
800
#
801
801
# iterates over the reserved and non-reserved field names of the table.
802
802
#
803
- # t = Tb.new %w[fruit color],
804
- # %w[apple red],
805
- # %w[banana yellow],
806
- # %w[orange orange]
803
+ # t = Tb.new %w[fruit color],
804
+ # %w[apple red],
805
+ # %w[banana yellow],
806
+ # %w[orange orange]
807
807
# pp t
808
808
# #=> #<Tb
809
809
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
@@ -862,7 +862,7 @@ def each_recordid
862
862
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
863
863
# # {"_recordid"=>1, "fruit"=>"banana", "color"=>"yellow"}
864
864
# # {"_recordid"=>2, "fruit"=>"orange", "color"=>"orange"}>
865
- # pp t.to_a
865
+ # pp t.to_a
866
866
# #=> [#<Tb::Record: "fruit"=>"apple", "color"=>"red">,
867
867
# # #<Tb::Record: "fruit"=>"banana", "color"=>"yellow">,
868
868
# # #<Tb::Record: "fruit"=>"orange", "color"=>"orange">]
@@ -892,7 +892,7 @@ def to_a
892
892
# # {"_recordid"=>0, "fruit"=>"apple", "color"=>"red"}
893
893
# # {"_recordid"=>1, "fruit"=>"banana", "color"=>"yellow"}
894
894
# # {"_recordid"=>2, "fruit"=>"orange", "color"=>"orange"}>
895
- # t.each_record {|record| p record }
895
+ # t.each_record {|record| p record }
896
896
# #=> #<Tb::Record: "fruit"=>"apple", "color"=>"red">
897
897
# # #<Tb::Record: "fruit"=>"banana", "color"=>"yellow">
898
898
# # #<Tb::Record: "fruit"=>"orange", "color"=>"orange">
@@ -918,7 +918,7 @@ def each_record_values(*fields)
918
918
# table.header_and_each(header_proc) {|record| ... }
919
919
#
920
920
# +header_and_each+ calls _header_proc_ at first.
921
- # The block is called for each record after that.
921
+ # The block is called for each record after that.
922
922
#
923
923
def header_and_each ( header_proc , &block )
924
924
header_proc . call ( list_fields ) if header_proc
@@ -952,7 +952,7 @@ def natjoin2(table2, missing=nil, retain_left=false, retain_right=false)
952
952
y . yield record . to_h
953
953
}
954
954
}
955
- er = t1 . natjoin2 ( t2 , missing , retain_left , retain_right )
955
+ er = t1 . natjoin2 ( t2 , missing , retain_left , retain_right )
956
956
result = nil
957
957
er . with_header { |header |
958
958
result = Tb . new header
@@ -984,7 +984,7 @@ def fmap!(field)
984
984
def delete_field ( *fields )
985
985
fields . each { |f |
986
986
f = check_field ( f )
987
- raise ArgumentError , "can not delete reserved field: #{ f . inspect } " if f . start_with? ( "_" )
987
+ raise ArgumentError , "can not delete reserved field: #{ f . inspect } " if f . start_with? ( "_" )
988
988
@tbl . delete ( f )
989
989
@field_list . delete ( f )
990
990
}
0 commit comments