webget_ruby_spreadsheeting 1.0.4 → 1.0.6

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.
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- $Nғjra�\qb��)WNwn���~,/B�$�����;���F�����o����?��������X��6�r.��˱$�@.�'
1
+ �/�f5���}H��y&k��xuCt(?ү&ʚ�%mΔ֋�:����M�A�c��!�;V��#Uք�X7!M�wHr�6�-G���A̾��zܮHCu9��<9�xm�8��Q�MƮ���X�|
@@ -6,3 +6,4 @@ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
6
6
  License:: CreativeCommons License, Non-commercial Share Alike
7
7
  License:: LGPL, GNU Lesser General Public License
8
8
 
9
+ Fusion key: A0M2R-72E46-K2V7Q-2N3K2
@@ -12,128 +12,183 @@ License:: LGPL, GNU Lesser General Public License
12
12
 
13
13
  module Spreadsheeting
14
14
 
15
- # Parse a string to a date, with some cleanup
16
- def import_date(s)
17
- return nil if s==nil or s.strip==''
18
- return Date.parse(s)
19
- end
20
-
21
-
22
- # There's a typical import use case where a column is
23
- # a boolean, in a variety of formats like "X" for on,
24
- # "Y" for yes, "T" for true, etc.
25
- #
26
- # @return a boolean
27
- #
28
- # We use these rules:
29
- # - x y yes t true on + => true
30
- # - blank n no f false off - => false
31
- # - anything else => nil
32
- #
33
- # ==Examples
34
- # import_flag('Yes') => true
35
- # import_flag('No') => false
36
- # import_flag('X') => true
37
- # import_flag('') => false
38
- # import_flag('Hello') => nil
39
- # import_flag(nil) => nil
40
-
41
- def import_flag(s)
42
- s==nil and return nil
43
- case s.strip.downcase
44
- when 'x','y','yes','t','true','on','+'
45
- return true
46
- when '','n','no','f','false','off','-'
47
- return false
48
- else
49
- return nil
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
- end
52
-
53
-
54
- # There's a typical import use case where a column
55
- # can contain two different data types:
56
- # - a boolean, in a variety of formats (see _import_flag_)
57
- # - a note, in plain text
58
- #
59
- # We need to separate these two.
60
- #
61
- # This method returns two items: a boolean and a note.
62
- #
63
- # We use these rules:
64
- # - x y yes t true on + => [true, '']
65
- # - blank n no f false off - => [false, '']
66
- # - any other string => [nil, note]
67
- # - nil => [nil, nil]
68
- #
69
- # ==Example
70
- # import_flag_or_note('Yes') => [true,'']
71
- # import_flag_or_note('No') => [false,'']
72
- # import_flag_or_note('X') => [true,'']
73
- # import_flag_or_note('') => [false,'']
74
- # import_flag_or_note('Hello') => [nil,'Hello']
75
- # import_flag_or_note(nil) => [nil,nil]
76
-
77
- def import_flag_or_note(s)
78
- return [nil, nil] if s==nil
79
- flag = import_flag(s)
80
- return [flag, flag==nil ? s : '']
81
- end
82
-
83
-
84
- # There's a common import use case where a column can be of two types:
85
- # - a date, in a variety of format like "Jan 1, 2008", "1/1/2008", etc.
86
- # - a note, in plain text
87
- #
88
- # This method returns two items: a date (Date class) and a note (String class).
89
- #
90
- # ==Example
91
- # import_date_or_note('1/1/2007') => [Date(2007,01,01),'']
92
- # import_date_or_note('hello') => [nil,'hello']
93
-
94
- def import_date_or_note(s)
95
- begin
96
- d=import_date(s)
97
- rescue
98
- d=nil
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('X', export_flag_or_note(true,'hello'))
39
- assert_equal('', export_flag_or_note(false,'hello'))
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
- d=Date.parse('2007/12/31')
45
- assert_equal('2007-12-31', export_date_or_note(d,'hello'))
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
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-02-19 00:00:00 -08:00
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