btucker-google_visualization 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ require 'rake/rdoctask'
2
+
3
+ CLEAN.include("doc")
4
+
5
+ # For a list of all attributes refer to http://rake.rubyforge.org/classes/Rake/RDocTask.html
6
+ Rake::RDocTask.new do |rd|
7
+ rd.title = "google_visualization-#{Google::Visualization::VERSION} Documentation"
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc", "LICENSE", "lib/**/*.rb")
10
+ rd.rdoc_dir = "doc"
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'rake/testtask'
2
+
3
+ namespace(:test) do
4
+
5
+ # For a list of all attributes refer to http://rake.rubyforge.org/classes/Rake/TestTask.html
6
+ Rake::TestTask.new(:unit) do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/**/tc_*.rb']
9
+ t.verbose = true
10
+ t.warning = true
11
+ end
12
+
13
+ end
@@ -0,0 +1 @@
1
+ {cols:[],rows:[]}
@@ -0,0 +1 @@
1
+ table = DataTable.new
@@ -0,0 +1 @@
1
+ {cols:[{label:"Task",type:"string"},{label:"Hours per Day",type:"number"}],rows:[{c:[{v:"Work"},{v:11}]},{c:[{v:"Eat"},{v:2}]},{c:[{v:"Commute"},{v:2}]},{c:[{v:"Watch TV"},{v:2}]},{c:[{v:"Sleep"},{v:7}]}]}
@@ -0,0 +1,8 @@
1
+ table = DataTable.new
2
+ table.add_column DataColumn.new(DataType::STRING, 'Task')
3
+ table.add_column DataColumn.new(DataType::NUMBER, 'Hours per Day')
4
+ table.add_row ['Work', 11]
5
+ table.add_row ['Eat', 2]
6
+ table.add_row ['Commute', 2]
7
+ table.add_row ['Watch TV', 2]
8
+ table.add_row ['Sleep', 7]
@@ -0,0 +1 @@
1
+ {cols:[{label:"Name",type:"string"},{label:"Salary",type:"number"},{label:"Full Time Employee",type:"boolean"}],rows:[{c:[{v:"Mike"},{v:10000,f:"$10,000"},{v:true}]},{c:[{v:"Jim"},{v:8000,f:"$8,000"},{v:false}]},{c:[{v:"Alice"},{v:12500,f:"$12,500"},{v:true}]},{c:[{v:"Bob"},{v:7000,f:"$7,000"},{v:true}]}]}
@@ -0,0 +1,8 @@
1
+ table = DataTable.new
2
+ table.add_column DataColumn.new(DataType::STRING, 'Name')
3
+ table.add_column DataColumn.new(DataType::NUMBER, 'Salary')
4
+ table.add_column DataColumn.new(DataType::BOOLEAN, 'Full Time Employee')
5
+ table.add_row ['Mike', DataCell.new(10000, '$10,000'), true]
6
+ table.add_row ['Jim', DataCell.new(8000, '$8,000'), false]
7
+ table.add_row ['Alice', DataCell.new(12500, '$12,500'), true]
8
+ table.add_row ['Bob', DataCell.new(7000, '$7,000'), true]
@@ -0,0 +1 @@
1
+ {cols:[{id:"A",label:"A-label",type:"string"},{id:"B",label:"B-label",type:"number"},{id:"C",label:"C-label",type:"date"}],rows:[{c:[{v:"a"},{v:1.0,f:"One"},{v:new Date(2000,0,1),f:"01/01/2000"}]},{c:[{v:"b"},{v:2.0,f:"Two"},{v:new Date(2000,0,2),f:"01/02/2000"}]},{c:[{v:"c"},{v:3.0,f:"Three"},{v:new Date(2000,0,3),f:"01/03/2000"}]}],p:{foo:"hello"}}
@@ -0,0 +1,8 @@
1
+ table = DataTable.new
2
+ table.store_custom_property(:foo, 'hello')
3
+ table.add_column DataColumn.new(DataType::STRING, 'A-label', 'A')
4
+ table.add_column DataColumn.new(DataType::NUMBER, 'B-label', 'B')
5
+ table.add_column DataColumn.new(DataType::DATE, 'C-label', 'C')
6
+ table.add_row ['a', DataCell.new(1.0, 'One'), DataCell.new(Date.parse("2000/01/01"), '01/01/2000')]
7
+ table.add_row ['b', DataCell.new(2.0, 'Two'), DataCell.new(Date.parse("2000/01/02"), '01/02/2000')]
8
+ table.add_row ['c', DataCell.new(3.0, 'Three'), DataCell.new(Date.parse("2000/01/03"), '01/03/2000')]
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'google_visualization'
3
+
4
+ include Google::Visualization
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), 'helper.rb')
2
+
3
+ class TC_DataCell < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ cell = DataCell.new
7
+ assert_not_nil(cell)
8
+ assert_instance_of(DataCell, cell)
9
+ end
10
+
11
+ def test_initialize_empty
12
+ cell = DataCell.new
13
+ assert_equal(cell.value, nil)
14
+ assert_equal(cell.formatted_value, nil)
15
+ end
16
+
17
+ def test_initialize_value
18
+ cell = DataCell.new('value')
19
+ assert_equal(cell.value, 'value')
20
+ end
21
+
22
+ def test_initialize_formatted_value
23
+ cell = DataCell.new(nil,'formatted_value')
24
+ assert_equal(cell.formatted_value, 'formatted_value')
25
+ end
26
+
27
+ def test_accessor_value
28
+ cell = DataCell.new
29
+ cell.value = 'value'
30
+ assert_equal(cell.value, 'value')
31
+ end
32
+
33
+ def test_accessor_formatted_value
34
+ cell = DataCell.new
35
+ cell.formatted_value = 'formatted_value'
36
+ assert_equal(cell.formatted_value, 'formatted_value')
37
+ end
38
+
39
+ def test_custom_properties
40
+ cell = DataCell.new
41
+ assert_equal(cell.is_a?(DataElement), true)
42
+ end
43
+
44
+ end
@@ -0,0 +1,76 @@
1
+ require File.join(File.dirname(__FILE__), 'helper.rb')
2
+
3
+ class TC_DataColumn < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ column = DataColumn.new
7
+ assert_not_nil(column)
8
+ assert_instance_of(DataColumn, column)
9
+ end
10
+
11
+ def test_initialize_empty
12
+ column = DataColumn.new
13
+ assert_equal(column.id, nil)
14
+ assert_equal(column.type, DataType::STRING)
15
+ assert_equal(column.label, nil)
16
+ assert_equal(column.pattern, "")
17
+ assert_equal(column.closed?, false)
18
+ end
19
+
20
+ def test_initialize_type
21
+ column = DataColumn.new(DataType::NUMBER)
22
+ assert_equal(column.type, DataType::NUMBER)
23
+ assert_raise(TypeError) { DataColumn.new(:STRING) }
24
+ end
25
+
26
+ def test_initialize_label
27
+ column = DataColumn.new(nil, 'label')
28
+ assert_equal(column.label, 'label')
29
+ end
30
+
31
+ def test_initialize_id
32
+ column = DataColumn.new(nil, nil, 'id')
33
+ assert_equal(column.id, 'id')
34
+ end
35
+
36
+ def test_accessor_id
37
+ column = DataColumn.new
38
+ column.id = 'id'
39
+ assert_equal(column.id, 'id')
40
+ end
41
+
42
+ def test_accessor_type
43
+ column = DataColumn.new
44
+ column.type = DataType::NUMBER
45
+ assert_equal(column.type, DataType::NUMBER)
46
+ assert_raise(TypeError) { column.type = :STRING }
47
+ end
48
+
49
+ def test_accessor_label
50
+ column = DataColumn.new
51
+ column.label = 'label'
52
+ assert_equal(column.label, 'label')
53
+ end
54
+
55
+ def test_accessor_pattern
56
+ column = DataColumn.new
57
+ column.pattern = 'pattern'
58
+ assert_equal(column.pattern, 'pattern')
59
+ end
60
+
61
+ def test_close
62
+ column = DataColumn.new
63
+ column.close
64
+ assert_equal(column.closed?, true)
65
+ assert_raise(StandardError) { column.type = DataType::NUMBER }
66
+ assert_nothing_raised { column.id = 'id' }
67
+ assert_nothing_raised { column.label = 'label' }
68
+ assert_nothing_raised { column.pattern = 'pattern' }
69
+ end
70
+
71
+ def test_custom_properties
72
+ column = DataColumn.new
73
+ assert_equal(column.is_a?(DataElement), true)
74
+ end
75
+
76
+ end
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), 'helper.rb')
2
+
3
+ class TC_DataElement < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ element = DataElement.new
7
+ assert_not_nil(element)
8
+ assert_instance_of(DataElement, element)
9
+ end
10
+
11
+ def test_initialize
12
+ element = DataElement.new
13
+ assert_equal(element.custom_properties_count, 0)
14
+ end
15
+
16
+ def test_store_custom_property
17
+ element = DataElement.new
18
+ element.store_custom_property('a', 0)
19
+ assert_equal(element.custom_properties_count, 1)
20
+ assert_equal(element.custom_property('a'), 0)
21
+ end
22
+
23
+ def test_store_custom_properties
24
+ element = DataElement.new
25
+ element.store_custom_properties({'a'=>0, 'b'=>1})
26
+ assert_equal(element.custom_properties_count, 2)
27
+ assert_equal(element.custom_property('a'), 0)
28
+ assert_equal(element.custom_property('b'), 1)
29
+ end
30
+
31
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), 'helper.rb')
2
+
3
+ class TC_DataRow < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ row = DataRow.new
7
+ assert_not_nil(row)
8
+ assert_instance_of(DataRow, row)
9
+ end
10
+
11
+ def test_initialize_empty
12
+ row = DataRow.new
13
+ assert_equal(row.cells_count, 0)
14
+ assert_equal(row.closed?, false)
15
+ end
16
+
17
+ def test_initialize_cells
18
+ row = DataRow.new(['value', DataCell.new(0)])
19
+ assert_equal(row.cells_count, 2)
20
+ end
21
+
22
+ def test_add_cell
23
+ row = DataRow.new
24
+ row.add_cell('value')
25
+ row.add_cell(DataCell.new(0))
26
+ assert_equal(row.cell(0).value, 'value')
27
+ assert_equal(row.cell(1).value, 0)
28
+ end
29
+
30
+ def test_add_cells
31
+ row = DataRow.new
32
+ row.add_cells(['value', DataCell.new(0)])
33
+ assert_equal(row.cell(0).value, 'value')
34
+ assert_equal(row.cell(1).value, 0)
35
+ end
36
+
37
+ def test_close
38
+ row = DataRow.new
39
+ row.close
40
+ assert_equal(row.closed?, true)
41
+ assert_raise(StandardError) { row.add_cell('value') }
42
+ end
43
+
44
+ def test_custom_properties
45
+ row = DataRow.new
46
+ assert_equal(row.is_a?(DataElement), true)
47
+ end
48
+
49
+ end
@@ -0,0 +1,124 @@
1
+ require File.join(File.dirname(__FILE__), 'helper.rb')
2
+
3
+ class TC_DataTable < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ table = DataTable.new
7
+ assert_not_nil(table)
8
+ assert_instance_of(DataTable, table)
9
+ end
10
+
11
+ def test_initialize_empty
12
+ table = DataTable.new
13
+ assert_equal(table.columns_count, 0)
14
+ assert_equal(table.rows_count, 0)
15
+ end
16
+
17
+ def test_initialize_columns
18
+ columns = [DataType::STRING, DataColumn.new(DataType::NUMBER)]
19
+ table = DataTable.new(columns)
20
+ assert_equal(table.columns_count, 2)
21
+ end
22
+
23
+ def test_initialize_rows
24
+ columns = [DataType::STRING, DataColumn.new(DataType::NUMBER)]
25
+ rows = [['value', 0], DataRow.new(['value', 1])]
26
+ assert_raise(StandardError) { DataTable.new(nil, rows) }
27
+ table = DataTable.new(columns, rows)
28
+ assert_equal(table.rows_count, 2)
29
+ end
30
+
31
+ def test_add_column
32
+ table = DataTable.new
33
+ table.add_column(DataType::STRING)
34
+ table.add_column(DataColumn.new(DataType::NUMBER))
35
+ assert_equal(table.columns_count, 2)
36
+ assert_equal(table.column(0).type, DataType::STRING)
37
+ assert_equal(table.column(1).type, DataType::NUMBER)
38
+ end
39
+
40
+ def test_add_columns
41
+ table = DataTable.new
42
+ table.add_columns([DataType::STRING, DataColumn.new(DataType::NUMBER)])
43
+ assert_equal(table.columns_count, 2)
44
+ assert_equal(table.column(0).type, DataType::STRING)
45
+ assert_equal(table.column(1).type, DataType::NUMBER)
46
+ end
47
+
48
+ def test_add_row
49
+ table = DataTable.new
50
+ assert_raise(StandardError) { table.add_row(['value', 0]) }
51
+ table.add_columns([DataType::STRING, DataColumn.new(DataType::NUMBER)])
52
+ table.add_row(['value', 0])
53
+ table.add_row(DataRow.new(['value', 1]))
54
+ assert_equal(table.rows_count, 2)
55
+ assert_equal(table.row(0).cell(1).value, 0)
56
+ assert_equal(table.row(1).cell(1).value, 1)
57
+ end
58
+
59
+ def test_add_rows
60
+ table = DataTable.new
61
+ assert_raise(StandardError) { table.add_rows([['value', 0], DataRow.new(['value', 1])]) }
62
+ table.add_columns([DataType::STRING, DataColumn.new(DataType::NUMBER)])
63
+ table.add_rows([['value', 0], DataRow.new(['value', 1])])
64
+ assert_equal(table.rows_count, 2)
65
+ assert_equal(table.row(0).cell(1).value, 0)
66
+ assert_equal(table.row(1).cell(1).value, 1)
67
+ end
68
+
69
+ def test_close
70
+ columns = [DataType::STRING, DataType::NUMBER]
71
+ rows = [['value', 0], ['value', 1]]
72
+ table = DataTable.new(columns, rows)
73
+ assert_raise(StandardError) { table.add_column(DataColumn.new(DataType::BOOLEAN)) }
74
+ assert_nothing_raised { table.add_row(['value', 2]) }
75
+ end
76
+
77
+ def test_sort_rows_single_column_ascending
78
+ columns = [DataType::STRING, DataType::NUMBER]
79
+ rows = [['value', 2], ['value', 0], ['value', 1]]
80
+ table = DataTable.new(columns, rows)
81
+ table.sort_rows!(:ascending, 1)
82
+ assert_equal(table.cell(0,1).value, 0)
83
+ assert_equal(table.cell(1,1).value, 1)
84
+ assert_equal(table.cell(2,1).value, 2)
85
+ end
86
+
87
+ def test_sort_rows_single_column_descending
88
+ columns = [DataType::STRING, DataType::NUMBER]
89
+ rows = [['value', 2], ['value', 0], ['value', 1]]
90
+ table = DataTable.new(columns, rows)
91
+ table.sort_rows!(:descending, 1)
92
+ assert_equal(table.cell(0,1).value, 2)
93
+ assert_equal(table.cell(1,1).value, 1)
94
+ assert_equal(table.cell(2,1).value, 0)
95
+ end
96
+
97
+ def test_sort_rows_multiple_columns_ascending
98
+ columns = [DataType::STRING, DataType::NUMBER, DataType::NUMBER]
99
+ rows = [['d', 2, 0], ['b', 1, 1], ['a', 1, 2], ['c', 0, 3]]
100
+ table = DataTable.new(columns, rows)
101
+ table.sort_rows!(:ascending, 1, 2)
102
+ assert_equal(table.cell(0,0).value, 'c')
103
+ assert_equal(table.cell(1,0).value, 'b')
104
+ assert_equal(table.cell(2,0).value, 'a')
105
+ assert_equal(table.cell(3,0).value, 'd')
106
+ end
107
+
108
+ def test_sort_rows_multiple_columns_descending
109
+ columns = [DataType::STRING, DataType::NUMBER, DataType::NUMBER]
110
+ rows = [['d', 2, 0], ['b', 1, 1], ['a', 1, 2], ['c', 0, 3]]
111
+ table = DataTable.new(columns, rows)
112
+ table.sort_rows!(:descending, 1, 2)
113
+ assert_equal(table.cell(0,0).value, 'd')
114
+ assert_equal(table.cell(1,0).value, 'a')
115
+ assert_equal(table.cell(2,0).value, 'b')
116
+ assert_equal(table.cell(3,0).value, 'c')
117
+ end
118
+
119
+ def test_custom_properties
120
+ table = DataTable.new
121
+ assert_equal(table.is_a?(DataElement), true)
122
+ end
123
+
124
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'helper.rb')
2
+
3
+ class TC_DataType < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ assert_raise(NoMethodError) { DataType.new }
7
+ end
8
+
9
+ def test_constants
10
+ assert_equal(DataType.const_defined?(:STRING), true)
11
+ assert_equal(DataType.const_defined?(:NUMBER), true)
12
+ assert_equal(DataType.const_defined?(:BOOLEAN), true)
13
+ assert_equal(DataType.const_defined?(:DATE), true)
14
+ assert_equal(DataType.const_defined?(:DATETIME), true)
15
+ assert_equal(DataType.const_defined?(:TIMEOFDAY), true)
16
+ assert_instance_of(DataType, DataType::STRING)
17
+ end
18
+
19
+ def test_to_s
20
+ assert_equal(DataType::STRING.to_s, "string")
21
+ assert_equal(DataType::NUMBER.to_s, "number")
22
+ assert_equal(DataType::BOOLEAN.to_s, "boolean")
23
+ assert_equal(DataType::DATE.to_s, "date")
24
+ assert_equal(DataType::DATETIME.to_s, "datetime")
25
+ assert_equal(DataType::TIMEOFDAY.to_s, "timeofday")
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: btucker-google_visualization
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 3
9
+ version: 0.5.3
10
+ platform: ruby
11
+ authors:
12
+ - Ben Tucker
13
+ - Miguel Fonseca
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-10 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Differs from original in that it uses the JSON gem to provide valid JSON.
34
+ email: ben@btucker.net
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.rdoc
42
+ files:
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.rdoc
46
+ - Rakefile
47
+ - btucker-google_visualization.gemspec
48
+ - lib/google_visualization.rb
49
+ - lib/google_visualization/data_cell.rb
50
+ - lib/google_visualization/data_column.rb
51
+ - lib/google_visualization/data_element.rb
52
+ - lib/google_visualization/data_row.rb
53
+ - lib/google_visualization/data_table.rb
54
+ - lib/google_visualization/data_type.rb
55
+ - lib/google_visualization/formatter.rb
56
+ - lib/google_visualization/formatter/csv.rb
57
+ - lib/google_visualization/formatter/json.rb
58
+ - tasks/ftp.rake
59
+ - tasks/rdoc.rake
60
+ - tasks/test.rake
61
+ - test/data/table1.json
62
+ - test/data/table1.rb
63
+ - test/data/table2.json
64
+ - test/data/table2.rb
65
+ - test/data/table3.json
66
+ - test/data/table3.rb
67
+ - test/data/table4.json
68
+ - test/data/table4.rb
69
+ - test/helper.rb
70
+ - test/tc_data_cell.rb
71
+ - test/tc_data_column.rb
72
+ - test/tc_data_element.rb
73
+ - test/tc_data_row.rb
74
+ - test/tc_data_table.rb
75
+ - test/tc_data_type.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/btucker/google_visualization
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A Ruby interface to manipulate and populate data for Google Interactive Charts.
106
+ test_files:
107
+ - test/data/table1.rb
108
+ - test/data/table2.rb
109
+ - test/data/table3.rb
110
+ - test/data/table4.rb
111
+ - test/helper.rb
112
+ - test/tc_data_cell.rb
113
+ - test/tc_data_column.rb
114
+ - test/tc_data_element.rb
115
+ - test/tc_data_row.rb
116
+ - test/tc_data_table.rb
117
+ - test/tc_data_type.rb