extcsv 0.12.2 → 0.12.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gemspec +1 -1
- data/lib/extcsv.rb +11 -8
- data/lib/extcsv_diagram.rb +10 -0
- data/rakefile +10 -10
- data/test/data/bsv.txt +5 -0
- data/test/test_extcsv.rb +16 -0
- data/test/test_extcsv_diagram.rb +4 -1
- metadata +14 -12
data/gemspec
CHANGED
data/lib/extcsv.rb
CHANGED
@@ -26,7 +26,7 @@ end
|
|
26
26
|
# Have a look at my other projects for
|
27
27
|
# correlation[http://extcsv.rubyforge.org/correlation] and {spectral filtering}[http://extcsv.rubyforge.org/spectralfilter].
|
28
28
|
#
|
29
|
-
# ==== Author: Ralf
|
29
|
+
# ==== Author: Ralf Mueller
|
30
30
|
# ==== License: BSD - see {license file}[http:/extcsv.rubyforge.org/svn/extcsv/trunk/LICENSE]
|
31
31
|
################################################################################
|
32
32
|
class ExtCsv < OpenStruct
|
@@ -36,7 +36,7 @@ class ExtCsv < OpenStruct
|
|
36
36
|
include Enumerable
|
37
37
|
|
38
38
|
# Allowed data types
|
39
|
-
TYPES = %w{csv ssv tsv psv txt plain}
|
39
|
+
TYPES = %w{csv ssv tsv psv bsv txt plain}
|
40
40
|
|
41
41
|
# Allowed input modes, db and url are not supported, yet
|
42
42
|
MODES = %w{file hash array string}
|
@@ -105,10 +105,11 @@ class ExtCsv < OpenStruct
|
|
105
105
|
|
106
106
|
def set_separators(obj_hash)
|
107
107
|
obj_hash[:cellsep] = case obj_hash[:datatype]
|
108
|
-
when "txt","tsv" then "\t"
|
109
|
-
when "ssv" then ';'
|
110
|
-
when "csv" then ','
|
111
|
-
when "psv" then "|"
|
108
|
+
when "txt","tsv" then "\t"# tab separated
|
109
|
+
when "ssv" then ';' # semikolon separated
|
110
|
+
when "csv" then ',' # comma separated
|
111
|
+
when "psv" then "|" # pipe separated
|
112
|
+
when "bsv" then " " # blank separated
|
112
113
|
end
|
113
114
|
obj_hash[:rowsep] = "\r\n"
|
114
115
|
end
|
@@ -128,7 +129,7 @@ class ExtCsv < OpenStruct
|
|
128
129
|
# * empty lines are removed
|
129
130
|
# * dots are changed into underscores for columns names
|
130
131
|
# * commas are converteed into dots (german number notation) unless the commy is the cell separator
|
131
|
-
# * the greek sign
|
132
|
+
# * the greek sign for mu is changes into mu
|
132
133
|
def parse_content(filecontent,obj_hash)
|
133
134
|
content = []
|
134
135
|
# convert numbers into us. notation if this doesn't crashes with the columns separator
|
@@ -156,7 +157,7 @@ class ExtCsv < OpenStruct
|
|
156
157
|
|
157
158
|
# further processing according to the input type
|
158
159
|
case obj_hash[:datatype]
|
159
|
-
when "csv","ssv","psv","txt","tsv"
|
160
|
+
when "csv","ssv","psv","txt","tsv","bsv"
|
160
161
|
# check if rows have the same lenght
|
161
162
|
contents_size = content.collect {|row| row.size}
|
162
163
|
content.each_with_index {|row,i|
|
@@ -735,6 +736,8 @@ class ExtCsvExporter
|
|
735
736
|
sep = "\t"
|
736
737
|
when "psv"
|
737
738
|
sep = "|"
|
739
|
+
when "bsv"
|
740
|
+
sep = " "
|
738
741
|
when "xml"
|
739
742
|
out = to_xml
|
740
743
|
when "tex"
|
data/lib/extcsv_diagram.rb
CHANGED
@@ -60,6 +60,9 @@ module ExtCsvDiagram
|
|
60
60
|
}
|
61
61
|
@@timeColumns = %w[time time_camera zeit date datetime timestamp]
|
62
62
|
|
63
|
+
@@ColorLow = 0x0000ad
|
64
|
+
@@ColorUp = 0xffffff
|
65
|
+
|
63
66
|
def ExtCsvDiagram.set_pointlabel(obj, plot, x_col, x, y, label_col=nil, size='10')
|
64
67
|
timemode = (%w[zeit zeitstempel time timestamp].include?(x_col.to_s))
|
65
68
|
x.each_index {|i|
|
@@ -160,6 +163,13 @@ module ExtCsvDiagram
|
|
160
163
|
plot.output options[:filename] + "." + options[:terminal].split(" ")[0]
|
161
164
|
end
|
162
165
|
|
166
|
+
def ExtCsvDiagram.colors(nColors)
|
167
|
+
colors = []
|
168
|
+
step = (@@ColorUp - @@ColorLow)/(nColors-1)
|
169
|
+
nColors.times {|i| colors << "#"+(@@ColorLow + i*step).to_s(16)}
|
170
|
+
olors
|
171
|
+
end
|
172
|
+
|
163
173
|
def ExtCsvDiagram.addDataToPlot(plot,obj,xColumn,yColumn,groupBy,options)
|
164
174
|
x = obj.send(xColumn)
|
165
175
|
y = obj.send(yColumn)
|
data/rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
begin
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'rubygems/package_task'
|
4
4
|
rescue Exception
|
5
5
|
nil
|
6
6
|
end
|
7
7
|
require 'rake/clean'
|
8
8
|
require 'rake/testtask'
|
9
|
-
require '
|
9
|
+
require 'rdoc/task'
|
10
10
|
|
11
11
|
CLEAN.include('**/*.out')
|
12
12
|
SPEC = eval(File.open("gemspec","r").read)
|
@@ -50,14 +50,14 @@ end
|
|
50
50
|
# ====================================================================
|
51
51
|
# Create a task that will package the software into distributable
|
52
52
|
# tar, zip and gem files.
|
53
|
-
if ! defined?(Gem)
|
54
|
-
|
55
|
-
else
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
53
|
+
# if ! defined?(Gem)
|
54
|
+
# puts "Package Target requires RubyGEMs"
|
55
|
+
# else
|
56
|
+
# package_task = GemPackageTask.new(SPEC) do |pkg|
|
57
|
+
# pkg.need_zip = false
|
58
|
+
# pkg.need_tar = false
|
59
|
+
# end
|
60
|
+
# end
|
61
61
|
|
62
62
|
# ====================================================================
|
63
63
|
desc "Build package for further developement"
|
data/test/data/bsv.txt
ADDED
data/test/test_extcsv.rb
CHANGED
@@ -37,6 +37,22 @@ class TestExtCsv < Test::Unit::TestCase
|
|
37
37
|
def test_create_csv
|
38
38
|
test_simple = ExtCsv.new(IMPORT_TYPE,"ssv",ERG_CSV_DATA)
|
39
39
|
end
|
40
|
+
def test_create_bsv
|
41
|
+
test_bsv = ExtCsv.new(IMPORT_TYPE,"bsv","/home/ram/src/git/extcsv/extcsv/trunk/test/data/bsv.txt")
|
42
|
+
assert_equal([1,5,11,55].map(&:to_s),test_bsv.a)
|
43
|
+
assert_equal(4,test_bsv.datacolumns.size)
|
44
|
+
assert_equal("d",test_bsv.datacolumns[-1])
|
45
|
+
if 'thingol' == `hostname`.chomp
|
46
|
+
cmt = ExtCsv.new(IMPORT_TYPE,"bsv","/home/ram/tmp/gmt/jp_00.cmt")
|
47
|
+
pp cmt.size
|
48
|
+
cmt_ = cmt.selectBy(:lon => "> 140",:lat => "> 30")
|
49
|
+
pp cmt_.sizea
|
50
|
+
filename = "bsv_from_bsv.txt"
|
51
|
+
cmt_.to_file(filename)
|
52
|
+
cmtFromCsv = ExtCsv.new(IMPORT_TYPE,"bsv",filename)
|
53
|
+
cmtFromCsv.datacolumns.each {|col| assert_equal(cmtFromCsv.send(col),cmt_.send(col)) }
|
54
|
+
end
|
55
|
+
end
|
40
56
|
def test_create_by_hash
|
41
57
|
simple = ExtCsv.new("hash","txt",{:col1 => ["80.0"],:col2 => ["625.0"]})
|
42
58
|
assert_equal(["80.0"],simple.col1)
|
data/test/test_extcsv_diagram.rb
CHANGED
@@ -29,7 +29,10 @@ class TestExtCsvDisplay < Test::Unit::TestCase
|
|
29
29
|
|
30
30
|
def test_simple
|
31
31
|
f=ExtCsv.new("file","txt",TEST_DATA)
|
32
|
-
ExtCsvDiagram.plot_xy(f,"col5","col3",'') #,"col0",["col1"])
|
32
|
+
ExtCsvDiagram.plot_xy(f,"col5","col3",'',:groupBy => ['col2']) #,"col0",["col1"])
|
33
|
+
end
|
34
|
+
def test_colors
|
35
|
+
pp ExtCsvDiagram.colors(21)
|
33
36
|
end
|
34
37
|
def _test_icon
|
35
38
|
icon = ExtCsv.new(IMPORT_TYPE,"psv",ICON)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extcsv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: stark.dreamdetective@gmail.com
|
@@ -17,22 +17,23 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- lib/extcsv.rb
|
20
21
|
- lib/lsmodel.rb
|
21
22
|
- lib/extcsv_diagram.rb
|
22
|
-
- lib/extcsv.rb
|
23
23
|
- rakefile
|
24
24
|
- gemspec
|
25
25
|
- LICENSE
|
26
26
|
- test/test_lsmodel.rb
|
27
|
-
- test/test_extcsv_diagram.rb
|
28
27
|
- test/test_extcsv.rb
|
29
|
-
- test/
|
28
|
+
- test/test_extcsv_diagram.rb
|
30
29
|
- test/data/file04.csv
|
31
|
-
- test/data/
|
30
|
+
- test/data/file05.csv
|
31
|
+
- test/data/bsv.txt
|
32
32
|
- test/data/file02.txt
|
33
|
+
- test/data/file00.txt
|
33
34
|
- test/data/file03.txt
|
34
|
-
- test/data/german.txt
|
35
35
|
- test/data/file01.txt
|
36
|
+
- test/data/german.txt
|
36
37
|
homepage: http://extcsv.rubyforge.org
|
37
38
|
licenses: []
|
38
39
|
post_install_message:
|
@@ -53,19 +54,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
54
|
version: '0'
|
54
55
|
requirements: []
|
55
56
|
rubyforge_project: extcsv
|
56
|
-
rubygems_version: 1.8.
|
57
|
+
rubygems_version: 1.8.23
|
57
58
|
signing_key:
|
58
59
|
specification_version: 3
|
59
60
|
summary: ! 'Let CSV-like files behave like DB-tables: selection, data operations on
|
60
61
|
columns. Easy plotting with gnuplot and modelling'
|
61
62
|
test_files:
|
62
63
|
- test/test_lsmodel.rb
|
63
|
-
- test/test_extcsv_diagram.rb
|
64
64
|
- test/test_extcsv.rb
|
65
|
-
- test/
|
65
|
+
- test/test_extcsv_diagram.rb
|
66
66
|
- test/data/file04.csv
|
67
|
-
- test/data/
|
67
|
+
- test/data/file05.csv
|
68
|
+
- test/data/bsv.txt
|
68
69
|
- test/data/file02.txt
|
70
|
+
- test/data/file00.txt
|
69
71
|
- test/data/file03.txt
|
70
|
-
- test/data/german.txt
|
71
72
|
- test/data/file01.txt
|
73
|
+
- test/data/german.txt
|