webget_ruby_spreadsheeting 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ $Nғj�r�a�\qb��)WNwn���~,/B�$�����;���F�����o����?��������X��6�r.��˱$�@.�'�
data/LICENSE.txt ADDED
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+
3
+ You may choose any of these licenses:
4
+
5
+ - CreativeCommons License, Non-commercial Share Alike
6
+ - LGPL, GNU Lesser General Public License
7
+ - MIT License
8
+ - Ruby License
9
+
10
+ THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
data/README.rdoc ADDED
@@ -0,0 +1,8 @@
1
+
2
+ = WebGet Ruby Gem: Spreadsheeting import & export helpers
3
+
4
+ Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
5
+ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
6
+ License:: CreativeCommons License, Non-commercial Share Alike
7
+ License:: LGPL, GNU Lesser General Public License
8
+
@@ -0,0 +1,139 @@
1
+ =begin rdoc
2
+
3
+ = WebGet Ruby Gem: Spreadsheeting import & export helpers
4
+
5
+ Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
6
+ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
7
+ License:: CreativeCommons License, Non-commercial Share Alike
8
+ License:: LGPL, GNU Lesser General Public License
9
+
10
+ =end
11
+
12
+
13
+ module Spreadsheeting
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
50
+ 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
99
+ 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
+
138
+
139
+ end
@@ -0,0 +1,49 @@
1
+ require 'test/unit'
2
+ require 'date'
3
+ require 'webget_ruby_spreadsheeting'
4
+
5
+ class SpreadsheetingTest < Test::Unit::TestCase
6
+
7
+ include Spreadsheeting
8
+
9
+ def test_import_flag
10
+ assert_equal(true, import_flag('X'))
11
+ assert_equal(false, import_flag(''))
12
+ assert_equal(true, import_flag('yes'))
13
+ assert_equal(false, import_flag('no'))
14
+ assert_equal(true, import_flag('+'))
15
+ assert_equal(false, import_flag('-'))
16
+ assert_equal(nil, import_flag('hello'))
17
+ assert_equal(nil, import_flag(nil))
18
+ end
19
+
20
+ def test_import_flag_or_note
21
+ assert_equal([true,''], import_flag_or_note('X'))
22
+ assert_equal([false,''], import_flag_or_note(''))
23
+ assert_equal([true,''], import_flag_or_note('yes'))
24
+ assert_equal([false,''], import_flag_or_note('no'))
25
+ assert_equal([true,''], import_flag_or_note('+'))
26
+ assert_equal([false,''], import_flag_or_note('-'))
27
+ assert_equal([nil,'hello'], import_flag_or_note('hello'))
28
+ assert_equal([nil,nil], import_flag_or_note(nil))
29
+ end
30
+
31
+ def test_import_date_or_note
32
+ d=Date.parse('2007/12/31')
33
+ assert_equal([d,''], import_date_or_note('2007/12/31'))
34
+ assert_equal([nil,'hello'], import_date_or_note('hello'))
35
+ end
36
+
37
+ 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'))
40
+ assert_equal('hello', export_flag_or_note(nil,'hello'))
41
+ end
42
+
43
+ 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'))
47
+ end
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webget_ruby_spreadsheeting
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - WebGet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDvDCCAyWgAwIBAgIJAIlSqEkDQaZIMA0GCSqGSIb3DQEBBQUAMIGbMQswCQYD
14
+ VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5j
15
+ aXNjbzETMBEGA1UEChMKV2ViR2V0LmNvbTETMBEGA1UECxMKV2ViR2V0LmNvbTET
16
+ MBEGA1UEAxMKV2ViR2V0LmNvbTEgMB4GCSqGSIb3DQEJARYRd2ViZ2V0QHdlYmdl
17
+ dC5jb20wHhcNMDkwMjI2MTk0NDU4WhcNMTExMTIzMTk0NDU4WjCBmzELMAkGA1UE
18
+ BhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lz
19
+ Y28xEzARBgNVBAoTCldlYkdldC5jb20xEzARBgNVBAsTCldlYkdldC5jb20xEzAR
20
+ BgNVBAMTCldlYkdldC5jb20xIDAeBgkqhkiG9w0BCQEWEXdlYmdldEB3ZWJnZXQu
21
+ Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXCFYfW6hCQl0ToNjaMIXG
22
+ ZfPF6OoR20BO/Tg6V37qPi7gDSZ6vIC6Mxcs8LtEcju85cD9lnKKl/lo4S5/w9Ha
23
+ hGD2ZFFfbF8420X5Za5G2KuriS3GzRz7F5dKCTjb1NH9TPlgOc71bcrDmCwwtFJl
24
+ T+tdfBju0YxLSBiMXf4y5QIDAQABo4IBBDCCAQAwHQYDVR0OBBYEFHB1kXO/Xd4g
25
+ G+AJ2/wwh6JOWXzNMIHQBgNVHSMEgcgwgcWAFHB1kXO/Xd4gG+AJ2/wwh6JOWXzN
26
+ oYGhpIGeMIGbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQG
27
+ A1UEBxMNU2FuIEZyYW5jaXNjbzETMBEGA1UEChMKV2ViR2V0LmNvbTETMBEGA1UE
28
+ CxMKV2ViR2V0LmNvbTETMBEGA1UEAxMKV2ViR2V0LmNvbTEgMB4GCSqGSIb3DQEJ
29
+ ARYRd2ViZ2V0QHdlYmdldC5jb22CCQCJUqhJA0GmSDAMBgNVHRMEBTADAQH/MA0G
30
+ CSqGSIb3DQEBBQUAA4GBADzVXlwuff0/w3yK4LflGKKhtC3oChIrwmSyP6tk628N
31
+ BHokpc4Kz63xSXqzYTnBS7rFBwlYThtNalQeWmoUjGh3Z0ZR0JlhU0ln8899LuJ3
32
+ DXnLFY0cVuBnNDMOOFl8vk1qIcZjcTovhzgcixpG6Uk5qmUsKHRLQf4oQJx7TfLK
33
+ -----END CERTIFICATE-----
34
+
35
+ date: 2010-02-19 00:00:00 -08:00
36
+ default_executable:
37
+ dependencies: []
38
+
39
+ description:
40
+ email: webget@webget.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - README.rdoc
49
+ - LICENSE.txt
50
+ - lib/webget_ruby_spreadsheeting.rb
51
+ has_rdoc: true
52
+ homepage: http://webget.com/
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: "WebGet Ruby Gem: Spreadsheeting import export helpers, to parse and prettify"
79
+ test_files:
80
+ - test/webget_ruby_spreadsheeting_test.rb
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ կa‡�I�x���-k� �V�e�jm�����,�(>T�2�A�m��ۻ��Y���,��>UI&��4z��?@g�S�V�������}הߵ+C@��|�������U�"��|Ĭ���}����7