SimpleOutput 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simplecsv.rb +77 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e3aaec36649b7fb39763828bd4317613e66cea1
|
4
|
+
data.tar.gz: 3e9351440698a5beb653cd02238fb71f85fee711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58117ba90da81536b687244318246cf3aea8d0ba46cca6f5eb13d28a0b0b75dff117e0e7357e56539c3be16acc7b932d212bc7b4ae77a44aaeae5b2dd4636986
|
7
|
+
data.tar.gz: 6ce9cff842588f8e1a445ce4d5cc75300a4ed2afe754907f78623be2a3c1334c0bcc46dda58f529cf6b643666d2e0d57920a752aae7e831f7bffb5ba1ff65eab
|
data/lib/simplecsv.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
=begin
|
2
|
+
SimpleCSV
|
3
|
+
Copyright 2014 Austen Higgins-Cassidy
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
=end
|
17
|
+
require 'csv'
|
18
|
+
|
19
|
+
class SimpleCSV < SimpleOutput::SimpleOutputPlugin
|
20
|
+
|
21
|
+
def initialize(file_template)
|
22
|
+
super()
|
23
|
+
@filename = file_template
|
24
|
+
@series_next = 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def options_callback(options)
|
28
|
+
if options.has_key?('xlabel')
|
29
|
+
@metadata[@current_name]['xlabel'] = options['xlabel']
|
30
|
+
end
|
31
|
+
if options.has_key?('ylabel')
|
32
|
+
@metadata[@current_name]['ylabel'] = options['ylabel']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def check_title(name, options)
|
37
|
+
if options.has_key?('series')
|
38
|
+
@metadata[name]['series_titles'] << options['series']
|
39
|
+
else
|
40
|
+
@metadata[name]['series_titles'] << "#{@metadata[name]['ylabel']}#{@series_next}"
|
41
|
+
@series_next += 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_x_callback(data, name, options)
|
46
|
+
check_title(name, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def new_data_callback(name)
|
50
|
+
name = translate_name(name)
|
51
|
+
@metadata[name] = {'xlabel' => "#{name}_x", 'ylabel' => "#{name}_y", 'series_titles' => []}
|
52
|
+
end
|
53
|
+
|
54
|
+
def append_callback(x,y,name,options)
|
55
|
+
if !@metadata.has_key?(name)
|
56
|
+
new_data_callback(name)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def save()
|
61
|
+
data = self.getDataAsXY()
|
62
|
+
data.each do |set_name, series|
|
63
|
+
CSV.open("#{@filename}_#{set_name}.csv", "wb") do |csv|
|
64
|
+
xlabel = @metadata[set_name]['xlabel']
|
65
|
+
|
66
|
+
series.each_with_index do |values, i|
|
67
|
+
values[0].unshift(xlabel)
|
68
|
+
csv << values[0]
|
69
|
+
ylabel = @metadata[set_name]['series_titles'].empty? ? @metadata[set_name]['ylabel'] : @metadata[set_name]['series_titles'][i]
|
70
|
+
values[1].unshift(ylabel)
|
71
|
+
csv << values[1]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SimpleOutput
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Austen Higgins-Cassidy
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- LICENSE
|
61
61
|
- include/chartkick.js
|
62
62
|
- lib/simplechartkick.rb
|
63
|
+
- lib/simplecsv.rb
|
63
64
|
- lib/simplelog.rb
|
64
65
|
- lib/simpleoutput.rb
|
65
66
|
- lib/simpleplot.rb
|