viewworkbook 0.3 → 1.1
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.
- checksums.yaml +4 -4
- data/bin/viewworkbook +10 -0
- data/doc/html/viewworkbook.html +370 -226
- data/doc/license.txt +14 -674
- data/doc/man/viewworkbook.1.gz +0 -0
- data/doc/rst/viewworkbook.rst +11 -0
- data/lib/column.rb +0 -2
- data/lib/sheetdata.rb +6 -7
- data/lib/sheetinterface.rb +41 -32
- data/lib/translating.rb +1 -2
- data/lib/user_input.rb +12 -10
- data/lib/viewworkbook.rb +8 -4
- data/viewworkbook.gemspec +18 -15
- metadata +116 -102
- data/lib/file_checking.rb +0 -112
data/lib/file_checking.rb
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
#encoding: UTF-8
|
|
2
|
-
=begin
|
|
3
|
-
/***************************************************************************
|
|
4
|
-
* ©2011-2024, Michael Uplawski <michael.uplawski@uplawski.eu> *
|
|
5
|
-
* *
|
|
6
|
-
* This program is free software; you can redistribute it and/or modify *
|
|
7
|
-
* it under the terms of the WTFPL 2.0 or later, see *
|
|
8
|
-
* http://www.wtfpl.net/about/ *
|
|
9
|
-
* *
|
|
10
|
-
* This program is distributed in the hope that it will be useful, *
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
13
|
-
* *
|
|
14
|
-
***************************************************************************/
|
|
15
|
-
=end
|
|
16
|
-
|
|
17
|
-
require 'filemagic'
|
|
18
|
-
|
|
19
|
-
=begin
|
|
20
|
-
A module to facilitate frequently occuring checks on
|
|
21
|
-
file-system objects
|
|
22
|
-
=end
|
|
23
|
-
module File_Checking
|
|
24
|
-
|
|
25
|
-
@@text_messages = {
|
|
26
|
-
:exist? => "does not exist!",
|
|
27
|
-
:exist => "does not exist!",
|
|
28
|
-
:readable? => "is not readable!",
|
|
29
|
-
:readable => "is not readable!",
|
|
30
|
-
:executable? => "is not executable!",
|
|
31
|
-
:executable => "is not executable!",
|
|
32
|
-
:writable? => "is not writable!",
|
|
33
|
-
:writable => "is not writable!",
|
|
34
|
-
:directory? => "is not a directory!",
|
|
35
|
-
:directory => "is not a directory!",
|
|
36
|
-
:file? => "is not a file!",
|
|
37
|
-
:file => "is not a file!",
|
|
38
|
-
:type => "is not of the sought file-type (not '%s', but '%s')!",
|
|
39
|
-
:type? => "is not of the sought file-type (not '%s', but '%s')!",
|
|
40
|
-
:mime => "does not have the sought mime-type (not '%s', but '%s')!",
|
|
41
|
-
:mime? => "does not have the sought mime-type (not '%s', but '%s')!",
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
# Checks if the file with the name from the first
|
|
45
|
-
# parameter has the properties, listed in the second.
|
|
46
|
-
# The messages parameter is an array of one or several
|
|
47
|
-
# of :exist?, :readable?, :writable?, :directory? or
|
|
48
|
-
# their string-representations, respectively.
|
|
49
|
-
# Returns nil in case of success, otherwise an
|
|
50
|
-
# informative message, describing the first negative
|
|
51
|
-
# test-result.
|
|
52
|
-
def file_check(file, *messages)
|
|
53
|
-
File_Checking.file_check(file, *messages)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Checks if the file with the name from the first
|
|
57
|
-
# parameter has the properties, listed in the second.
|
|
58
|
-
# The messages parameter is an array of one or all
|
|
59
|
-
# of :exist?, :readable?, :writable?, :directory? or
|
|
60
|
-
# their string-representations, respectively.
|
|
61
|
-
# Returns nil in case of success, otherwise an
|
|
62
|
-
# informative message, describing the first negative
|
|
63
|
-
# test-result.
|
|
64
|
-
def self.file_check(file, *messages)
|
|
65
|
-
msg = nil
|
|
66
|
-
if(file && messages.respond_to?(:to_ary) && !messages.empty?)
|
|
67
|
-
messages.each do |k|
|
|
68
|
-
if(! k.to_s.end_with?('?'))
|
|
69
|
-
k = (k.to_s << '?').to_sym
|
|
70
|
-
end
|
|
71
|
-
@log.debug ('checking ' << k.to_s) if @log
|
|
72
|
-
if(msg == nil && File.respond_to?(k) && ! File.send(k, file.to_s))
|
|
73
|
-
msg = "#{file} #{@@text_messages[k.to_sym]}"
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
msg
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def self.mime_check(file, mime_type)
|
|
81
|
-
fm = FileMagic.mime
|
|
82
|
-
fd = fm.fd(File.new(file) ).split(';')[0]
|
|
83
|
-
if fd != mime_type.strip
|
|
84
|
-
return file.dup << ' ' << (@@text_messages[:mime] %[mime_type, fd])
|
|
85
|
-
end
|
|
86
|
-
return nil
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def self.magic_check(file, magic)
|
|
90
|
-
fm = FileMagic.fm
|
|
91
|
-
fd = fm.fd(File.new(file) ).split(';')[0]
|
|
92
|
-
if fd != magic.strip
|
|
93
|
-
return file.dup << ' ' << (@@text_messages[:type] %[magic, fd])
|
|
94
|
-
end
|
|
95
|
-
return nil
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
end # module
|
|
99
|
-
|
|
100
|
-
=begin
|
|
101
|
-
# example
|
|
102
|
-
|
|
103
|
-
include File_Checking
|
|
104
|
-
msg = file_check('some_file.txt', [:exist?, :readable?, 'writable'])
|
|
105
|
-
# same as
|
|
106
|
-
# msg = file_check('some_file.txt', [:exist, :readable, 'writable?'])
|
|
107
|
-
|
|
108
|
-
msg ||= magic_check('some_file.txt', [:type?], 'OpenDocument Text'
|
|
109
|
-
msg ||= mime_check('some_file.txt', [:mime?], 'application/vnd.oasis.opendocument.text'
|
|
110
|
-
puts msg if msg
|
|
111
|
-
=end
|
|
112
|
-
# E O F
|