tchart 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/bin/tchart +5 -0
  3. data/lib/tchart.rb +27 -0
  4. data/lib/tchart/lang/tchart_error.rb +9 -0
  5. data/lib/tchart/model/bar.rb +24 -0
  6. data/lib/tchart/model/chart.rb +25 -0
  7. data/lib/tchart/model/command_line_args.rb +18 -0
  8. data/lib/tchart/model/coordinate.rb +29 -0
  9. data/lib/tchart/model/grid_line.rb +25 -0
  10. data/lib/tchart/model/label.rb +43 -0
  11. data/lib/tchart/model/layout.rb +85 -0
  12. data/lib/tchart/model/separator.rb +28 -0
  13. data/lib/tchart/model/settings.rb +68 -0
  14. data/lib/tchart/model/y_item.rb +44 -0
  15. data/lib/tchart/process/chart_builder.rb +63 -0
  16. data/lib/tchart/process/command_line_parser.rb +73 -0
  17. data/lib/tchart/process/data_parser.rb +76 -0
  18. data/lib/tchart/process/data_reader.rb +14 -0
  19. data/lib/tchart/process/items_parser.rb +156 -0
  20. data/lib/tchart/process/layout_builder.rb +106 -0
  21. data/lib/tchart/process/settings_parser.rb +63 -0
  22. data/lib/tchart/process/tex_builder.rb +85 -0
  23. data/lib/tchart/process/tex_writer.rb +13 -0
  24. data/lib/tchart/version.rb +3 -0
  25. data/test/integration_test.rb +82 -0
  26. data/test/tchart/model/bar_test.rb +17 -0
  27. data/test/tchart/model/coordinate_test.rb +10 -0
  28. data/test/tchart/model/grid_line_test.rb +17 -0
  29. data/test/tchart/model/label_test.rb +31 -0
  30. data/test/tchart/model/layout_test.rb +17 -0
  31. data/test/tchart/model/separator_test.rb +19 -0
  32. data/test/tchart/model/settings_test.rb +48 -0
  33. data/test/tchart/model/y_item_test.rb +24 -0
  34. data/test/tchart/process/chart_builder_test.rb +33 -0
  35. data/test/tchart/process/command_line_parser_test.rb +89 -0
  36. data/test/tchart/process/data_parser_test.rb +60 -0
  37. data/test/tchart/process/data_reader_test.rb +23 -0
  38. data/test/tchart/process/items_parser_test.rb +154 -0
  39. data/test/tchart/process/layout_builder_test.rb +189 -0
  40. data/test/tchart/process/settings_parser_test.rb +75 -0
  41. data/test/tchart/process/tex_builder_test.rb +120 -0
  42. data/test/tchart/process/tex_writer_test.rb +38 -0
  43. data/test/tchart_test.rb +47 -0
  44. metadata +154 -0
@@ -0,0 +1,75 @@
1
+ require_relative "../../test_helper"
2
+
3
+ module TChart
4
+ describe SettingsParser, "parse" do
5
+
6
+ before do
7
+ @parser = SettingsParser.new
8
+ end
9
+
10
+ it "returns true if the passed line is recognized as a setting" do
11
+ @parser.parse?("chart_width=42").must_equal true
12
+ @parser.parse?("chart_width = 42").must_equal true
13
+ end
14
+
15
+ it "returns false if the passed line is not recognizable as a setting" do
16
+ @parser.parse?("C++ | lang | 2003").must_equal false
17
+ end
18
+
19
+ it "parses settings with no sign" do
20
+ @parser.parse?("chart_width=42\n")
21
+ @parser.settings.chart_width.must_equal 42
22
+ end
23
+
24
+ it "parses settings with a plus sign" do
25
+ @parser.parse?("chart_width=+42\n")
26
+ @parser.settings.chart_width.must_equal 42
27
+ end
28
+
29
+ it "parses settings with a minus sign" do
30
+ @parser.parse?("chart_width=-42\n")
31
+ @parser.settings.chart_width.must_equal (-42)
32
+ end
33
+
34
+ it "parses settings with a decimal but no decimal places" do
35
+ @parser.parse?("chart_width=42.\n")
36
+ @parser.settings.chart_width.must_equal 42
37
+ end
38
+
39
+ it "parses settings with decimal places" do
40
+ @parser.parse?("chart_width=42.24\n")
41
+ @parser.settings.chart_width.must_equal 42.24
42
+ end
43
+
44
+ it "parses settings with trailing zeros after the decimal place" do
45
+ @parser.parse?("chart_width=42.240\n")
46
+ @parser.settings.chart_width.must_equal 42.24
47
+ end
48
+
49
+ it "parses settings with leading zeros" do
50
+ @parser.parse?("chart_width=0042\n")
51
+ @parser.settings.chart_width.must_equal 42
52
+ end
53
+
54
+ it "ignores spaces around the equals sign in a setting" do
55
+ @parser.parse?("chart_width = 42\n")
56
+ @parser.settings.chart_width.must_equal 42
57
+ end
58
+
59
+ it "ignores leading spaces before the setting name" do
60
+ @parser.parse?(" chart_width=42\n")
61
+ @parser.settings.chart_width.must_equal 42
62
+ end
63
+
64
+ it "returns an error if the settings value is not a number for numeric settings" do
65
+ error = ->{ @parser.parse?("chart_width=42mm\n") }.must_raise TChartError
66
+ error.message.must_equal "\"42mm\" is not a recognizable setting value; expecting e.g. 123 or 123.45"
67
+ end
68
+
69
+ it "returns an error if the setting name is unknown" do
70
+ error = ->{ @parser.parse?("unknown=42\n") }.must_raise TChartError
71
+ error.message.must_match( /^unknown setting \"unknown\"; expecting one of:/ )
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,120 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module TChart
4
+ describe TeXBuilder, "begin_chart" do
5
+
6
+ before do
7
+ @tex = TeXBuilder.new
8
+ end
9
+
10
+ it "generates \\tikzpicture" do
11
+ @tex.begin_chart
12
+ @tex.to_s.must_equal "\\tikzpicture\n"
13
+ end
14
+
15
+ end
16
+
17
+
18
+ describe TeXBuilder, "end_chart" do
19
+
20
+ before do
21
+ @tex = TeXBuilder.new
22
+ end
23
+
24
+ it "generates \\endtikzpicture" do
25
+ @tex.end_chart
26
+ @tex.to_s.must_equal "\\endtikzpicture\n"
27
+ end
28
+
29
+ end
30
+
31
+
32
+ describe TeXBuilder, "comment" do
33
+
34
+ before do
35
+ @tex = TeXBuilder.new
36
+ end
37
+
38
+ it "generates a TeX comment" do
39
+ @tex.comment "this is a comment"
40
+ @tex.to_s.must_equal "% this is a comment\n"
41
+ end
42
+
43
+ it "escapes TeX special characters in comments" do
44
+ @tex.comment '# $ % & _ { } \ ~ ^ |'
45
+ @tex.to_s.must_include '\# \$ \% \& \_ \{ \} $\backslash$ \~{} \^{} $\vert$'
46
+ end
47
+
48
+ it "handles non-string arguments" do
49
+ @tex.comment 123
50
+ @tex.to_s.must_equal "% 123\n"
51
+ end
52
+
53
+ end
54
+
55
+
56
+ describe TeXBuilder, "gridline" do
57
+
58
+ before do
59
+ @tex = TeXBuilder.new
60
+ end
61
+
62
+ it "generates a TikZ code for a grid line" do
63
+ @tex.gridline xy(10,20), xy(30,40), "line_style" # x1, y1, x2, y2, style
64
+ @tex.to_s.must_equal "\\draw [line_style] (10.00mm, 20.00mm) -- (30.00mm, 40.00mm);\n"
65
+ end
66
+
67
+ end
68
+
69
+
70
+ describe TeXBuilder, "label" do
71
+
72
+ before do
73
+ @tex = TeXBuilder.new
74
+ end
75
+
76
+ it "generates TikZ code for a chart label" do
77
+ @tex.label xy(10,20), 15, 'some_style', 'the label text' # x_mid, y, width, style, text
78
+ @tex.to_s.must_equal "\\node [some_style, text width = 15.00mm] at (10.00mm, 20.00mm) {the label text};\n"
79
+ end
80
+
81
+ it "escapes TeX special characters in the label text" do
82
+ @tex.label xy(10,20), 15, 'some_style', 'TeX special characters: # $ % & _ { } \ ~ ^ |' # x_mid, y, width, style, text
83
+ @tex.to_s.must_include '{TeX special characters: \# \$ \% \& \_ \{ \} $\backslash$ \~{} \^{} $\vert$}'
84
+ end
85
+
86
+ it "handles non-string label text" do
87
+ @tex.label xy(10,20), 15, 'some_style', 123 # x_mid, y, width, style, text
88
+ @tex.to_s.must_equal "\\node [some_style, text width = 15.00mm] at (10.00mm, 20.00mm) {123};\n"
89
+ end
90
+
91
+ end
92
+
93
+
94
+ describe TeXBuilder, "bar" do
95
+
96
+ before do
97
+ @tex = TeXBuilder.new
98
+ end
99
+
100
+ it "generates TikZ code for a horizontal bar on the chart" do
101
+ @tex.bar xy(10,50), xy(40,50), 'some_style' # from, to, style
102
+ @tex.to_s.must_equal "\\node [some_style] at (25.00mm, 50.00mm) [minimum width = 30.00mm] {};\n"
103
+ end
104
+
105
+ end
106
+
107
+
108
+ describe TeXBuilder, "to_s" do
109
+
110
+ before do
111
+ @tex = TeXBuilder.new
112
+ end
113
+
114
+ it "returns the generated TeX code" do
115
+ @tex.comment "a comment"
116
+ @tex.to_s.must_equal "% a comment\n"
117
+ end
118
+
119
+ end
120
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module TChart
4
+ describe TeXWriter, "write" do
5
+
6
+ before do
7
+ @filename = "_test_.tex"
8
+ @content = "some content\n"
9
+ File.delete(@filename) if File.exists?(@filename)
10
+ end
11
+
12
+ after do
13
+ File.delete(@filename) if File.exists?(@filename)
14
+ end
15
+
16
+ it "writes output" do
17
+ TeXWriter.write(@filename, @content)
18
+ File.exists?(@filename).must_equal true
19
+ IO.read(@filename).must_equal @content
20
+ end
21
+
22
+ it "silently overwrites an already existing output file" do
23
+ File.open(@filename, 'w') { |f| f.write('should be overwritten') }
24
+ TeXWriter.write(@filename, @content)
25
+ IO.read(@filename).must_equal @content
26
+ end
27
+
28
+ it "throws a 'not writable' error if the output file already exists and cannot be overwritten" do
29
+ begin
30
+ Dir.mkdir(@filename)
31
+ proc { TeXWriter.write(@filename, @content) }.must_raise Errno::EISDIR
32
+ ensure
33
+ Dir.rmdir(@filename)
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'test_helper'
2
+
3
+ module TChart
4
+ describe TChart do
5
+
6
+ before do
7
+ @argv = ["smoke_test.txt", "smoke_test.tex"]
8
+ File.open(@argv[0], 'w') {|f| f.puts("skill \t style \t 2001-2005\n---")}
9
+ end
10
+
11
+ after do
12
+ @argv.each { |filename| File.delete(filename) if File.exist?(filename) }
13
+ end
14
+
15
+ it "is silent when everything runs successfully" do
16
+ proc { TChart.run(@argv) }.must_be_silent
17
+ end
18
+
19
+ it "writes errors and aborts if command line argument errors are found" do
20
+ CommandLineParser.stubs(:parse).returns [ stub, [ 'an error'] ]
21
+ proc do
22
+ proc do
23
+ TChart.run(@argv)
24
+ end.must_raise SystemExit
25
+ end.must_output nil, "an error\n"
26
+ end
27
+
28
+ it "writes errors and aborts if parsing errors are found" do
29
+ DataReader.stubs(:read).returns [ stub, stub, [ 'an error' ] ]
30
+ proc do
31
+ proc do
32
+ TChart.run(@argv)
33
+ end.must_raise SystemExit
34
+ end.must_output nil, "an error\n"
35
+ end
36
+
37
+ it "writes errors and aborts if layout errors are found" do
38
+ LayoutBuilder.stubs(:build).returns [ stub, [ 'an error' ] ]
39
+ proc do
40
+ proc do
41
+ TChart.run(@argv)
42
+ end.must_raise SystemExit
43
+ end.must_output nil, "an error\n"
44
+ end
45
+
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tchart
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Lewandowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mocha
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ description: " tchart reads a text file containing
56
+ date-based data,\n for example employment history,
57
+ and generates TikZ\n code to render a chart of
58
+ the data. The generated \n TikZ chart can then
59
+ be embedded in a TeX or LaTeX\n document, such
60
+ as a resume.\n"
61
+ email: milewdev@gmail.com
62
+ executables:
63
+ - tchart
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - lib/tchart/lang/tchart_error.rb
68
+ - lib/tchart/model/bar.rb
69
+ - lib/tchart/model/chart.rb
70
+ - lib/tchart/model/command_line_args.rb
71
+ - lib/tchart/model/coordinate.rb
72
+ - lib/tchart/model/grid_line.rb
73
+ - lib/tchart/model/label.rb
74
+ - lib/tchart/model/layout.rb
75
+ - lib/tchart/model/separator.rb
76
+ - lib/tchart/model/settings.rb
77
+ - lib/tchart/model/y_item.rb
78
+ - lib/tchart/process/chart_builder.rb
79
+ - lib/tchart/process/command_line_parser.rb
80
+ - lib/tchart/process/data_parser.rb
81
+ - lib/tchart/process/data_reader.rb
82
+ - lib/tchart/process/items_parser.rb
83
+ - lib/tchart/process/layout_builder.rb
84
+ - lib/tchart/process/settings_parser.rb
85
+ - lib/tchart/process/tex_builder.rb
86
+ - lib/tchart/process/tex_writer.rb
87
+ - lib/tchart/version.rb
88
+ - lib/tchart.rb
89
+ - test/integration_test.rb
90
+ - test/tchart/model/bar_test.rb
91
+ - test/tchart/model/coordinate_test.rb
92
+ - test/tchart/model/grid_line_test.rb
93
+ - test/tchart/model/label_test.rb
94
+ - test/tchart/model/layout_test.rb
95
+ - test/tchart/model/separator_test.rb
96
+ - test/tchart/model/settings_test.rb
97
+ - test/tchart/model/y_item_test.rb
98
+ - test/tchart/process/chart_builder_test.rb
99
+ - test/tchart/process/command_line_parser_test.rb
100
+ - test/tchart/process/data_parser_test.rb
101
+ - test/tchart/process/data_reader_test.rb
102
+ - test/tchart/process/items_parser_test.rb
103
+ - test/tchart/process/layout_builder_test.rb
104
+ - test/tchart/process/settings_parser_test.rb
105
+ - test/tchart/process/tex_builder_test.rb
106
+ - test/tchart/process/tex_writer_test.rb
107
+ - test/tchart_test.rb
108
+ - bin/tchart
109
+ homepage: https://github.com/milewdev/tchart
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ~>
120
+ - !ruby/object:Gem::Version
121
+ version: '2'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements:
128
+ - Ruby 2
129
+ - A TeX distribution (e.g. tug.org/mactex) to render the generated TikZ chart code.
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.14
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Generate TikZ code to plot date-based data.
135
+ test_files:
136
+ - test/integration_test.rb
137
+ - test/tchart/model/bar_test.rb
138
+ - test/tchart/model/coordinate_test.rb
139
+ - test/tchart/model/grid_line_test.rb
140
+ - test/tchart/model/label_test.rb
141
+ - test/tchart/model/layout_test.rb
142
+ - test/tchart/model/separator_test.rb
143
+ - test/tchart/model/settings_test.rb
144
+ - test/tchart/model/y_item_test.rb
145
+ - test/tchart/process/chart_builder_test.rb
146
+ - test/tchart/process/command_line_parser_test.rb
147
+ - test/tchart/process/data_parser_test.rb
148
+ - test/tchart/process/data_reader_test.rb
149
+ - test/tchart/process/items_parser_test.rb
150
+ - test/tchart/process/layout_builder_test.rb
151
+ - test/tchart/process/settings_parser_test.rb
152
+ - test/tchart/process/tex_builder_test.rb
153
+ - test/tchart/process/tex_writer_test.rb
154
+ - test/tchart_test.rb