webget_ruby_spreadsheeting 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -1
- data/README.rdoc +1 -0
- data/lib/webget_ruby_spreadsheeting.rb +175 -120
- data/test/webget_ruby_spreadsheeting_test.rb +20 -5
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
�/�f�5���}H��y&k��xuC�t(?ү&ʚ�%mΔ�:����M�A�c��!�;V��#Uք�X7!M�wHr�6�-G���A̾��zܮH�Cu�9��<9�xm�8��Q�MƮ���X�|
|
data/README.rdoc
CHANGED
@@ -12,128 +12,183 @@ License:: LGPL, GNU Lesser General Public License
|
|
12
12
|
|
13
13
|
module Spreadsheeting
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
15
|
+
|
16
|
+
# Convert true/false to "+"/"-"
|
17
|
+
#
|
18
|
+
# @param [Boolean] flag
|
19
|
+
# @return [String] "+" or "-"
|
20
|
+
|
21
|
+
def export_flag(flag)
|
22
|
+
flag ? '+' : '-'
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Corresponds to import_flag_or_note
|
27
|
+
#
|
28
|
+
# - flag==true => "+"
|
29
|
+
# - flag==false => "-"
|
30
|
+
# - flag==nil => note
|
31
|
+
#
|
32
|
+
# @return [String] "+" or "-" or freeform string note
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# export_flag_or_note(true,"hello") => "+"
|
36
|
+
# export_flag_or_note(false,"hello") => "-"
|
37
|
+
# export_flag_or_note(nil,"hello") => "hello"
|
38
|
+
#
|
39
|
+
# @see #import_flag_or_note
|
40
|
+
# @see #export_flag
|
41
|
+
|
42
|
+
def export_flag_or_note(flag,note=nil)
|
43
|
+
return flag==nil ? note : export_flag(flag)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Convert a date to a string format "YYYY/MM/DD"
|
48
|
+
#
|
49
|
+
# @param [Boolean] flag
|
50
|
+
# @return [String] "+" or "-"
|
51
|
+
|
52
|
+
def export_date(date)
|
53
|
+
date.strftime("%Y/%m/%d")
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# Corresponds to import_date_or_note
|
58
|
+
#
|
59
|
+
# - date is non-null => "2007/12/31"
|
60
|
+
# - date is null => note
|
61
|
+
#
|
62
|
+
# @return [String] a date formatted like "2007/12/31" or freeform string note
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# d=Date.parse('1/1/2007')
|
66
|
+
# export_date_or_note(d,'hello') => '2007-01-01'
|
67
|
+
# export_date_or_note(nil,'hello') => 'hello'
|
68
|
+
#
|
69
|
+
# @see #import_date_or_note
|
70
|
+
|
71
|
+
def export_date_or_note(date,note=nil)
|
72
|
+
return date==nil ? note : export_date(date)
|
50
73
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
74
|
+
|
75
|
+
|
76
|
+
# Parse a string to a date, with some cleanup.
|
77
|
+
#
|
78
|
+
# @param [String, #to_s, nil] input to parse, e.g. "2007/12/31"
|
79
|
+
# @return [Date] the parsed date
|
80
|
+
#
|
81
|
+
# @see #import_date_or_note
|
82
|
+
|
83
|
+
def import_date(input)
|
84
|
+
return nil if input==nil
|
85
|
+
input_s = input.to_s.strip
|
86
|
+
return nil if input==''
|
87
|
+
return Date.parse(input_s)
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# Parse an imput that may be a date (e.g. "2007/12/31") or a note (e.g. freeform text) into an array.
|
92
|
+
#
|
93
|
+
# There's a common import use case where a column can be of two types:
|
94
|
+
# - a date, in a variety of format like "Jan 1, 2008", "1/1/2008", etc.
|
95
|
+
# - a note, in plain text
|
96
|
+
#
|
97
|
+
# @param [Boolean, String, #to_s, nil] input typically "Yes", "No", "On", "Off", etc.
|
98
|
+
# @return [Array<Date, String>] the parsed output [date, note]
|
99
|
+
#
|
100
|
+
# @example
|
101
|
+
# import_date_or_note('1/1/2007') => [Date(2007,01,01),'']
|
102
|
+
# import_date_or_note('hello') => [nil,'hello']
|
103
|
+
#
|
104
|
+
# @see #export_date_or_note
|
105
|
+
# @see #import_date
|
106
|
+
|
107
|
+
def import_date_or_note(input)
|
108
|
+
begin
|
109
|
+
d=import_date(input)
|
110
|
+
rescue
|
111
|
+
d=nil
|
112
|
+
end
|
113
|
+
return d ? [d,''] : [nil,input]
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
# Parse various input words (e.g. "Yes", "No", "On", "Off") to true or false.
|
118
|
+
#
|
119
|
+
# There's a typical import use case where a column is
|
120
|
+
# a boolean, in a variety of formats like "X" for on,
|
121
|
+
# "Y" for yes, "T" for true, etc.
|
122
|
+
#
|
123
|
+
# We use these rules:
|
124
|
+
# - x y yes t true on + => true
|
125
|
+
# - blank n no f false off - => false
|
126
|
+
# - anything else => nil
|
127
|
+
#
|
128
|
+
# @param [Boolean, String, #to_s, nil] input typically "Yes", "No", "On", "Off", etc.
|
129
|
+
# @return [Boolean] the parsed output
|
130
|
+
#
|
131
|
+
# @example
|
132
|
+
# import_flag("Yes") => true
|
133
|
+
# import_flag("No") => false
|
134
|
+
# import_flag("X") => true
|
135
|
+
# import_flag("") => false
|
136
|
+
# import_flag("Hello") => nil
|
137
|
+
# import_flag(true) => true
|
138
|
+
# import_flag(false) => true
|
139
|
+
# import_flag(nil) => nil
|
140
|
+
#
|
141
|
+
# @see #import_flag_or_note
|
142
|
+
|
143
|
+
def import_flag(input)
|
144
|
+
return input if (input==true or input==false or input==nil)
|
145
|
+
case input.to_s.strip.downcase
|
146
|
+
when 'x','y','yes','t','true','on','+'
|
147
|
+
return true
|
148
|
+
when '','n','no','f','false','off','-'
|
149
|
+
return false
|
150
|
+
else
|
151
|
+
return nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
# Parse an imput that may be a flag (e.g. true/false) or a note (e.g. freeform text) into an array.
|
157
|
+
#
|
158
|
+
# There's a typical import use case where a column
|
159
|
+
# can contain two different data types:
|
160
|
+
# - a boolean, in a variety of formats (see _import_flag_)
|
161
|
+
# - a note, in plain text
|
162
|
+
#
|
163
|
+
# We need to separate these two.
|
164
|
+
#
|
165
|
+
# We use these rules:
|
166
|
+
# - x y yes t true on + => [true, '']
|
167
|
+
# - blank n no f false off - => [false, '']
|
168
|
+
# - any other string => [nil, note]
|
169
|
+
# - nil => [nil, nil]
|
170
|
+
#
|
171
|
+
# @param [Boolean, String, #to_s, nil] input typically "Yes", "No", "On", "Off", etc.
|
172
|
+
# @return [Array<Boolean, String>] the parsed output [flag, note]
|
173
|
+
#
|
174
|
+
# @example
|
175
|
+
# import_flag_or_note("Yes") => [true,""]
|
176
|
+
# import_flag_or_note("No") => [false,""]
|
177
|
+
# import_flag_or_note("X") => [true,""]
|
178
|
+
# import_flag_or_note("") => [false,""]
|
179
|
+
# import_flag_or_note("Hello") => [nil,"Hello"]
|
180
|
+
# import_flag_or_note(true) => [true,""]
|
181
|
+
# import_flag_or_note(false) => [false,""]
|
182
|
+
# import_flag_or_note(nil) => [nil,nil]
|
183
|
+
#
|
184
|
+
# @see #export_flag_or_note
|
185
|
+
# @see #import_flag
|
186
|
+
|
187
|
+
def import_flag_or_note(input)
|
188
|
+
return [nil, nil] if (input==nil)
|
189
|
+
flag = import_flag(input)
|
190
|
+
return [flag, flag==nil ? input : '']
|
99
191
|
end
|
100
|
-
return d ? [d,''] : [nil,s]
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
# Corresponds to import_flag_or_note
|
105
|
-
#
|
106
|
-
# ==Return
|
107
|
-
# - flag==true => 'X'
|
108
|
-
# - flag==false => ''
|
109
|
-
# - otherwise return note
|
110
|
-
#
|
111
|
-
# ==Example
|
112
|
-
# t=true
|
113
|
-
# f=false
|
114
|
-
# export_flag_or_note(t,'hello') => 'X'
|
115
|
-
# export_flag_or_note(f,'hello') => ''
|
116
|
-
# export_flag_or_note(nil,'hello') => 'hello'
|
117
|
-
|
118
|
-
def export_flag_or_note(flag,note=nil)
|
119
|
-
return flag==true ? 'X' : flag==false ? '' : note
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
# Corresponds to import_date_or_note
|
124
|
-
#
|
125
|
-
# ==Return
|
126
|
-
# - date exists => date to yyyy-mm-dd format
|
127
|
-
# - otherwise return note
|
128
|
-
#
|
129
|
-
# ==Example
|
130
|
-
# d=Date.parse('1/1/2007')
|
131
|
-
# export_date_or_note(d,'hello') => '2007-01-01'
|
132
|
-
# export_date_or_note(nil,'hello') => 'hello'
|
133
|
-
|
134
|
-
def export_date_or_note(date,note=nil)
|
135
|
-
return date ? date.strftime("%Y-%m-%d") : note
|
136
|
-
end
|
137
192
|
|
138
193
|
|
139
194
|
end
|
@@ -6,6 +6,9 @@ class SpreadsheetingTest < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
include Spreadsheeting
|
8
8
|
|
9
|
+
DATE_STR="2007/12/31"
|
10
|
+
DATE=Date.parse(DATE_STR)
|
11
|
+
|
9
12
|
def test_import_flag
|
10
13
|
assert_equal(true, import_flag('X'))
|
11
14
|
assert_equal(false, import_flag(''))
|
@@ -14,6 +17,8 @@ class SpreadsheetingTest < Test::Unit::TestCase
|
|
14
17
|
assert_equal(true, import_flag('+'))
|
15
18
|
assert_equal(false, import_flag('-'))
|
16
19
|
assert_equal(nil, import_flag('hello'))
|
20
|
+
assert_equal(true, import_flag(true))
|
21
|
+
assert_equal(false, import_flag(false))
|
17
22
|
assert_equal(nil, import_flag(nil))
|
18
23
|
end
|
19
24
|
|
@@ -25,6 +30,8 @@ class SpreadsheetingTest < Test::Unit::TestCase
|
|
25
30
|
assert_equal([true,''], import_flag_or_note('+'))
|
26
31
|
assert_equal([false,''], import_flag_or_note('-'))
|
27
32
|
assert_equal([nil,'hello'], import_flag_or_note('hello'))
|
33
|
+
assert_equal([true,''], import_flag_or_note(true))
|
34
|
+
assert_equal([false,''], import_flag_or_note(false))
|
28
35
|
assert_equal([nil,nil], import_flag_or_note(nil))
|
29
36
|
end
|
30
37
|
|
@@ -34,16 +41,24 @@ class SpreadsheetingTest < Test::Unit::TestCase
|
|
34
41
|
assert_equal([nil,'hello'], import_date_or_note('hello'))
|
35
42
|
end
|
36
43
|
|
44
|
+
def test_export_flag
|
45
|
+
assert_equal('+', export_flag(true))
|
46
|
+
assert_equal('-', export_flag(false))
|
47
|
+
end
|
48
|
+
|
37
49
|
def test_export_flag_or_note
|
38
|
-
assert_equal('
|
39
|
-
assert_equal('',
|
50
|
+
assert_equal('+', export_flag_or_note(true,'hello'))
|
51
|
+
assert_equal('-', export_flag_or_note(false,'hello'))
|
40
52
|
assert_equal('hello', export_flag_or_note(nil,'hello'))
|
41
53
|
end
|
42
54
|
|
55
|
+
def test_export_date
|
56
|
+
assert_equal(DATE_STR,export_date(DATE))
|
57
|
+
end
|
58
|
+
|
43
59
|
def test_export_date_or_note
|
44
|
-
|
45
|
-
assert_equal('
|
46
|
-
assert_equal('hello', export_date_or_note(nil,'hello'))
|
60
|
+
assert_equal(DATE_STR, export_date_or_note(DATE,'hello'))
|
61
|
+
assert_equal('hello', export_date_or_note(nil,'hello'))
|
47
62
|
end
|
48
63
|
|
49
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webget_ruby_spreadsheeting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WebGet
|
@@ -32,7 +32,7 @@ cert_chain:
|
|
32
32
|
DXnLFY0cVuBnNDMOOFl8vk1qIcZjcTovhzgcixpG6Uk5qmUsKHRLQf4oQJx7TfLK
|
33
33
|
-----END CERTIFICATE-----
|
34
34
|
|
35
|
-
date: 2010-
|
35
|
+
date: 2010-03-18 00:00:00 -07:00
|
36
36
|
default_executable:
|
37
37
|
dependencies: []
|
38
38
|
|
metadata.gz.sig
CHANGED
Binary file
|