viewworkbook 0.1.3

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.
@@ -0,0 +1,89 @@
1
+ #encoding: UTF-8
2
+ =begin
3
+ /***************************************************************************
4
+ * ©2011-2014, Michael Uplawski *
5
+ * <michael.uplawski@uplawski.eu> *
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************/
22
+ =end
23
+
24
+
25
+ RD = File.expand_path(File.dirname(__FILE__) ) + File::SEPARATOR if !defined?(RD)
26
+
27
+ require 'yaml'
28
+ require_relative 'file_checking'
29
+
30
+
31
+ # A way to produce translated text in a ruby-program.
32
+ # Translations are read from a file "translations" in the program folder.
33
+ module Translating
34
+ # There are better ways to extend a translated
35
+ # string, but I keep the 'wild-card' for
36
+ # historical reasons.
37
+ @@awild = 'XX'
38
+
39
+ @@lang = nil
40
+ @@lang_file = format("%s%s", RD, 'LANG')
41
+ @@tr = YAML::load_file("#{RD}translations")
42
+
43
+ # find the current language-setting and return it.
44
+ def self.language()
45
+ if @@lang == nil
46
+ r = ENV['LANG']
47
+ if(r)
48
+ @@lang = r[0, 2]
49
+ elsif( !File_Checking::file_check(@@lang_file, [:exist?, :readable?]) && File::size(@@lang_file) >= 2)
50
+ File::open(@@lang_file, 'r') {|f| @@lang = f.readline}
51
+ @@lang.chomp!.downcase! if @@lang
52
+ end
53
+ end
54
+ @@lang = 'en' if !@@lang
55
+ end
56
+
57
+ # Translate a string to the currently set langage.
58
+ # The args parameter may contain replacement-text which
59
+ # will appear at the positions indicated by wildcard-characters
60
+ # in the original string.
61
+ def self.trl(t, *args)
62
+ Translating::language()
63
+ lt = @@tr[t]
64
+ if(lt)
65
+ lt = lt[@@lang]
66
+ else
67
+ # File.open('/tmp/mtf', 'a+') {|f| f << t << "\n"}
68
+ puts "\nTRANSLATION MISSING: \"" << t << "\""
69
+ end
70
+ lt ||= t
71
+ if(args && !args.empty?)
72
+ i = -1
73
+ lt = lt.gsub(@@awild) do |a|
74
+ i += 1
75
+ args.flatten[i]
76
+ end
77
+ lt += args[i + 1, args.length].join
78
+ end
79
+ return lt
80
+ end
81
+
82
+ # Translate a string to the currently set langage.
83
+ # The args parameter may contain replacement-text which
84
+ # will appear at the positions indicated by wildcard-characters
85
+ # in the original string.
86
+ def trl(t, *args )
87
+ Translating::trl(t, args)
88
+ end
89
+ end
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2011, Michael Uplawski <michael.uplawski@uplawski.eu>
2
+ # This program is free software; you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation; either version 3 of the License, or
5
+ # (at your option) any later version.
6
+ #
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program; if not, write to the
14
+ # Free Software Foundation, Inc.,
15
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+ # =========================================================================
17
+ # These are the messages printed by Viewworkbook. The first line of each
18
+ # block is the original english message, the following lines contain the
19
+ # translations for different locales.
20
+
21
+ # Keep this key 'Viewworkbook' as it is
22
+
23
+ Viewworkbook:
24
+
25
+
26
+ # EOF
@@ -0,0 +1,52 @@
1
+ #encoding: UTF-8
2
+
3
+ =begin
4
+ /***************************************************************************
5
+ * Copyright © 2014-2017, Michael Uplawski <michael.uplawski@uplawski.eu>*
6
+ * *
7
+ * This program is free software; you can redistribute it and/or modify *
8
+ * it under the terms of the GNU General Public License as published by *
9
+ * the Free Software Foundation; either version 3 of the License, or *
10
+ * (at your option) any later version. *
11
+ * *
12
+ * This program is distributed in the hope that it will be useful, *
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
+ * GNU General Public License for more details. *
16
+ * *
17
+ * You should have received a copy of the GNU General Public License *
18
+ * along with this program; if not, write to the *
19
+ * Free Software Foundation, Inc., *
20
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
+ ***************************************************************************/
22
+ =end
23
+
24
+ require 'io/wait'
25
+ require 'io/console'
26
+
27
+ # unblocking read from STDIN
28
+
29
+ def wait_for_user()
30
+ char = nil
31
+ # char = STDIN.raw(&:getc)
32
+ STDIN.raw do
33
+ STDIN.noecho do
34
+ until (STDIN.ready?)
35
+ sleep(0.1)
36
+ end
37
+
38
+ char = (STDIN.read_nonblock(1).ord rescue nil)
39
+ end
40
+ end
41
+ return char
42
+ end
43
+
44
+ def debout(str)
45
+ if $DEBUG == :DEBUG
46
+ puts str
47
+ if(wait_for_user().chr == 'q')
48
+ exit true
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: UTF-8
3
+
4
+ =begin
5
+ /******************************************************************************
6
+ * Copyright © 2014-2016, Michael Uplawski <michael.uplawski@uplawski.eu> *
7
+ * *
8
+ * This program is free software; you can redistribute it and/or modify *
9
+ * it under the terms of the GNU General Public License as published by *
10
+ * the Free Software Foundation; either version 3 of the License, or *
11
+ * (at your option) any later version. *
12
+ * *
13
+ * This program is distributed in the hope that it will be useful, *
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
+ * GNU General Public License for more details. *
17
+ * *
18
+ * You should have received a copy of the GNU General Public License *
19
+ * along with this program; if not, write to the *
20
+ * Free Software Foundation, Inc., *
21
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22
+ ******************************************************************************/
23
+ =end
24
+
25
+ require_relative 'logging'
26
+ require_relative 'file_checking'
27
+ require_relative 'sheetinterface'
28
+ require_relative 'sheetdata'
29
+ require_relative 'color_output'
30
+
31
+ require 'roo'
32
+ require 'roo-xls'
33
+ require 'tempfile'
34
+
35
+ class ViewWorkBook
36
+ include Logging
37
+ include File_Checking
38
+
39
+ attr_reader :workbook
40
+
41
+ def initialize(*args)
42
+ init_logger(STDOUT, Logger::INFO)
43
+ @log.debug('args is ' << args.to_s)
44
+ wb = args[0]
45
+ path = File.path(wb) if wb
46
+ @log.debug('workbook file will be ' << (path ? path : 'N I L'))
47
+
48
+ if(wb)
49
+ msg = file_check(path, :exist?, :file?, :readable?)
50
+ if(!msg)
51
+ begin
52
+ @workbook = SheetData.workbook(path)
53
+ view_sheet if @workbook
54
+ end
55
+ else
56
+ @log.error(yellow("Cannot open " << path << ": " << msg))
57
+ # raise IOError.new(msg)
58
+ puts red("\n\tPlease name a valid spreadsheet file! Aborting.")
59
+ puts
60
+ exit false
61
+ end
62
+ end
63
+ @log.debug('initialized')
64
+ end
65
+
66
+ def method_missing(method, *args)
67
+ @workbook.send(method.to_sym, *args)
68
+ end
69
+
70
+ def sheet(number)
71
+ view_sheet(number)
72
+ end
73
+
74
+ private
75
+ def view_sheet(number = 0)
76
+ @log.debug('default_sheet is ' << sheets[number])
77
+ SheetInterface.new(@workbook, number)
78
+ end
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ ViewWorkBook.new(ARGV)
83
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viewworkbook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Michael Uplawski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.4.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.4.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: roo-xls
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: ruby-filemagic
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.7'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.7.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.7'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.7.1
73
+ description: View spreadsheet files in a text-console.
74
+ email: michael.uplawski@uplawski.eu
75
+ executables:
76
+ - viewworkbook
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - bin/viewworkbook
81
+ - doc/html/viewworkbook.html
82
+ - doc/license.txt
83
+ - doc/man/viewworkbook.1.gz
84
+ - doc/rst/viewworkbook.rst
85
+ - lib/action.rb
86
+ - lib/busy_indicator/busy_function_test.rb
87
+ - lib/busy_indicator/busy_indicator.rb
88
+ - lib/cell.rb
89
+ - lib/color_output.rb
90
+ - lib/column.rb
91
+ - lib/file_checking.rb
92
+ - lib/log.conf
93
+ - lib/logging.rb
94
+ - lib/menu.rb
95
+ - lib/row.rb
96
+ - lib/scrollable.rb
97
+ - lib/sheetdata.rb
98
+ - lib/sheetinterface.rb
99
+ - lib/translating.rb
100
+ - lib/translations
101
+ - lib/user_input.rb
102
+ - lib/viewworkbook.rb
103
+ homepage: http://rubygems.org
104
+ licenses:
105
+ - GPL-3.0
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.1.2
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements:
122
+ - roo, roo-xls, filemagic
123
+ rubyforge_project:
124
+ rubygems_version: 2.7.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: bugfix, gzipped man-page
128
+ test_files: []