webget_ruby_ramp 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data.tar.gz.sig +0 -0
  2. data/lib/webget_ruby_ramp.rb +250 -0
  3. data/lib/webget_ruby_ramp/active_record.rb +119 -0
  4. data/lib/webget_ruby_ramp/active_record/connection_adapters/abstract/schema_statements.rb +24 -0
  5. data/lib/webget_ruby_ramp/active_record/save_extensions.rb +35 -0
  6. data/lib/webget_ruby_ramp/array.rb +370 -0
  7. data/lib/webget_ruby_ramp/csv.rb +53 -0
  8. data/lib/webget_ruby_ramp/date.rb +90 -0
  9. data/lib/webget_ruby_ramp/enumerable.rb +385 -0
  10. data/lib/webget_ruby_ramp/file.rb +15 -0
  11. data/lib/webget_ruby_ramp/hash.rb +223 -0
  12. data/lib/webget_ruby_ramp/integer.rb +22 -0
  13. data/lib/webget_ruby_ramp/io.rb +65 -0
  14. data/lib/webget_ruby_ramp/kernel.rb +36 -0
  15. data/lib/webget_ruby_ramp/math.rb +20 -0
  16. data/lib/webget_ruby_ramp/nil.rb +17 -0
  17. data/lib/webget_ruby_ramp/numeric.rb +98 -0
  18. data/lib/webget_ruby_ramp/object.rb +20 -0
  19. data/lib/webget_ruby_ramp/process.rb +153 -0
  20. data/lib/webget_ruby_ramp/string.rb +221 -0
  21. data/lib/webget_ruby_ramp/symbol.rb +11 -0
  22. data/lib/webget_ruby_ramp/time.rb +11 -0
  23. data/lib/webget_ruby_ramp/xml.rb +193 -0
  24. data/lib/webget_ruby_ramp/yaml.rb +34 -0
  25. data/test/webget_ruby_ramp/active_record/connection_adapters/abstract/schema_statements_test.rb +9 -0
  26. data/test/webget_ruby_ramp/active_record/save_extensions_test.rb +7 -0
  27. data/test/webget_ruby_ramp/active_record_test.rb +64 -0
  28. data/test/webget_ruby_ramp/array_test.rb +171 -0
  29. data/test/webget_ruby_ramp/csv_test.rb +18 -0
  30. data/test/webget_ruby_ramp/date_test.rb +60 -0
  31. data/test/webget_ruby_ramp/enumerable_test.rb +275 -0
  32. data/test/webget_ruby_ramp/file_test.rb +15 -0
  33. data/test/webget_ruby_ramp/hash_test.rb +105 -0
  34. data/test/webget_ruby_ramp/integer_test.rb +19 -0
  35. data/test/webget_ruby_ramp/io_test.rb +31 -0
  36. data/test/webget_ruby_ramp/io_test.txt +1 -0
  37. data/test/webget_ruby_ramp/kernel_test.rb +15 -0
  38. data/test/webget_ruby_ramp/math_test.rb +17 -0
  39. data/test/webget_ruby_ramp/nil_test.rb +15 -0
  40. data/test/webget_ruby_ramp/numeric_test.rb +28 -0
  41. data/test/webget_ruby_ramp/object_test.rb +12 -0
  42. data/test/webget_ruby_ramp/process_test.rb +24 -0
  43. data/test/webget_ruby_ramp/string_test.rb +125 -0
  44. data/test/webget_ruby_ramp/symbol_test.rb +26 -0
  45. data/test/webget_ruby_ramp/time_test.rb +12 -0
  46. data/test/webget_ruby_ramp/xml_test.rb +93 -0
  47. data/test/webget_ruby_ramp/xml_test_1.xml +5 -0
  48. data/test/webget_ruby_ramp/xml_test_2.xml +5 -0
  49. data/test/webget_ruby_ramp/xml_test_msword_clean.html +1 -0
  50. data/test/webget_ruby_ramp/xml_test_msword_dirty.html +148 -0
  51. data/test/webget_ruby_ramp/yaml_test.rb +32 -0
  52. data/test/webget_ruby_ramp/yaml_test_1.yml +38 -0
  53. data/test/webget_ruby_ramp/yaml_test_2.yml +38 -0
  54. metadata +128 -0
  55. metadata.gz.sig +1 -0
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class FileTestCase < Test::Unit::TestCase
5
+
6
+ def test_load_dir_files
7
+ filename='/a/b/c.d'
8
+ dirname=File.dirname(filename)
9
+ expect=File.join(dirname,'x','y','z')
10
+ actual=File.joindir(filename,'x','y','z')
11
+ assert_equal(expect,actual,"filename:#{filename} dirname:#{dirname}")
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,105 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class HashTest < Test::Unit::TestCase
5
+
6
+
7
+ def test_size
8
+ h = {'a'=>'b'}
9
+ assert(h.size?)
10
+ h = {}
11
+ assert(!h.size?)
12
+ end
13
+
14
+
15
+ def test_each_key
16
+ actual = { "a" => "b", "c" => "d" }
17
+ expect = { "A" => "b", "C" => "d" }
18
+ actual.each_key! {|key| key.upcase }
19
+ assert_equal(expect,actual)
20
+ end
21
+
22
+
23
+ def test_each_pair
24
+ actual = { "a" => "b", "c" => "d" }
25
+ expect = { "A" => "B", "C" => "D" }
26
+ actual.each_pair! {|key,value| [key.upcase, value.upcase] }
27
+ assert_equal(expect,actual)
28
+ end
29
+
30
+
31
+ def test_each_value
32
+ actual = { "a" => "b", "c" => "d" }
33
+ expect = { "a" => "B", "c" => "D" }
34
+ actual.each_value! {|value| value.upcase }
35
+ assert_equal(expect,actual)
36
+ end
37
+
38
+
39
+ def test_map_pair
40
+ h = {"a"=>"b", "c"=>"d", "e"=>"f" }
41
+ expect=["ab","cd","ef"]
42
+ actual=h.map_pair{|key,value| key+value }.sort
43
+ assert_equal(expect,actual,h.inspect)
44
+ end
45
+
46
+
47
+ def pivotable
48
+ h=Hash.new
49
+ h['a']=Hash.new
50
+ h['b']=Hash.new
51
+ h['c']=Hash.new
52
+ h['a']['x']='m'
53
+ h['a']['y']='n'
54
+ h['a']['z']='o'
55
+ h['b']['x']='p'
56
+ h['b']['y']='q'
57
+ h['b']['z']='r'
58
+ h['c']['x']='s'
59
+ h['c']['y']='t'
60
+ h['c']['z']='u'
61
+ return h
62
+ end
63
+
64
+
65
+ def test_pivot_vals
66
+ p=pivotable.pivot(:vals)
67
+ assert_equal(['x','y','z'], p.keys.sort)
68
+ assert_equal(['m','p','s'], p['x'].sort)
69
+ assert_equal(['n','q','t'], p['y'].sort)
70
+ assert_equal(['o','r','u'], p['z'].sort)
71
+ end
72
+
73
+
74
+ def test_pivot_vals_with_block
75
+ p=pivotable.pivot(:vals){|items| items.sort.inject{|sum,x| sum+=x}}
76
+ assert_equal(['x','y','z'], p.keys.sort)
77
+ assert_equal('mps', p['x'])
78
+ assert_equal('nqt', p['y'])
79
+ assert_equal('oru', p['z'])
80
+ end
81
+
82
+
83
+ def test_pivot_keys
84
+ p=pivotable.pivot(:keys)
85
+ assert_equal(['a','b','c'], p.keys.sort)
86
+ assert_equal(['m','n','o'], p['a'].sort)
87
+ assert_equal(['p','q','r'], p['b'].sort)
88
+ assert_equal(['s','t','u'], p['c'].sort)
89
+ end
90
+
91
+
92
+ def test_pivot_keys_with_block
93
+ p=pivotable.pivot(:keys){|items| items.sort.inject{|sum,x| sum+=x}}
94
+ assert_equal(['a','b','c'], p.keys.sort)
95
+ assert_equal('mno', p['a'])
96
+ assert_equal('pqr', p['b'])
97
+ assert_equal('stu', p['c'])
98
+ end
99
+
100
+
101
+ end
102
+
103
+
104
+
105
+
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class IntegerTest < Test::Unit::TestCase
5
+
6
+ def test_maps
7
+ expect=['a','a','a']
8
+ actual=3.maps{'a'}
9
+ assert_equal(expect,actual)
10
+ end
11
+
12
+ def test_maps_with_index
13
+ expect=[0,1,2]
14
+ actual=3.maps{|i| i}
15
+ assert_equal(expect,actual)
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class IOTest < Test::Unit::TestCase
5
+
6
+ MYDIR=File.join('test','webget_ruby_ramp')
7
+
8
+ def test_load_dir_files
9
+ dirpath=File.join(MYDIR,'io_test*')
10
+ expect=[File.join(MYDIR,'io_test.rb'),File.join(MYDIR,'io_test.txt')]
11
+ actual=Dir[dirpath].sort
12
+ assert_equal(expect,actual,"Dir[#{dirpath}] expects test data files")
13
+ end
14
+
15
+ def test_readrow
16
+ filename=Dir[File.join(MYDIR,'io_test.txt')].first
17
+ f=File.open(filename)
18
+ assert_equal(["A1","B1","C1"],f.readrow(:row=>"=",:col=>"-"))
19
+ assert_equal(["A2","B2","C2"],f.readrow(:row=>"=",:col=>"-"))
20
+ assert_equal(["A3","B3","C3"],f.readrow(:row=>"=",:col=>"-"))
21
+ end
22
+
23
+ def test_readrows
24
+ filename=Dir[File.join(MYDIR,'io_test.txt')].first
25
+ expect=[["A1","B1","C1"],["A2","B2","C2"],["A3","B3","C3"]]
26
+ actual=IO.readrows(filename,:row=>"=",:col=>"-")
27
+ assert_equal(expect,actual)
28
+ end
29
+
30
+ end
31
+
@@ -0,0 +1 @@
1
+ A1-B1-C1=A2-B2-C2=A3-B3-C3
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class KernelTest < Test::Unit::TestCase
5
+
6
+ def test_method_name
7
+ assert_equal('test_method_name',method_name)
8
+ end
9
+
10
+ def test_pp_s
11
+ assert_equal(":foo\n",pp_s(:foo))
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class MathTest < Test::Unit::TestCase
5
+
6
+ def test_ln
7
+ assert_equal(1.0,Math.ln(Math.exp(1.0)))
8
+ end
9
+
10
+ def test_logn
11
+ assert_equal(1.0,Math.logn(3,3),'log of 3 base 3')
12
+ assert_equal(2.0,Math.logn(9,3),'log of 9 base 3')
13
+ assert_equal(3.0,Math.logn(27,3),'log of 27 base 3')
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class NilTest < Test::Unit::TestCase
5
+
6
+ def test_blank
7
+ assert_equal(true,nil.blank?)
8
+ end
9
+
10
+ def test_size
11
+ assert_equal(false,nil.size?)
12
+ end
13
+
14
+ end
15
+
@@ -0,0 +1,28 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class NumericTest < Test::Unit::TestCase
5
+
6
+
7
+ def test_if_with_true
8
+ assert_equal(5,5.if(true))
9
+ end
10
+
11
+
12
+ def test_if_with_false
13
+ assert_equal(0,5.if(false))
14
+ end
15
+
16
+
17
+ def test_unless_with_true
18
+ assert_equal(0,5.unless(true))
19
+ end
20
+
21
+
22
+ def test_unless_with_false
23
+ assert_equal(5,5.unless(false))
24
+ end
25
+
26
+
27
+ end
28
+
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class ObjectTest < Test::Unit::TestCase
5
+
6
+ def test_in_array
7
+ assert_equal(true,'a'.in?(['a','b','c']))
8
+ assert_equal(false,'x'.in?(['a','b','c']))
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,24 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+ class ProcessTest < Test::Unit::TestCase
5
+
6
+ include Process
7
+
8
+ def test_ps
9
+ p=Process.ps
10
+ assert(p!=nil,"ps != nil")
11
+ assert(p.is_a?(String),"ps is a string")
12
+ assert(p.size>0,"ps size > 0")
13
+ end
14
+
15
+ def test_pss
16
+ p=Process.pss
17
+ assert(p!=nil,"pss != nil")
18
+ assert(p.is_a?(Hash),"ps_hash is a hash")
19
+ assert(p.size>0,"pss size > 0")
20
+ assert(p['pcpu']!=nil,"ps_hash pcpu != nil")
21
+ end
22
+
23
+ end
24
+
@@ -0,0 +1,125 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+
5
+ class StringTest < Test::Unit::TestCase
6
+
7
+
8
+ def test_capitalize_words
9
+ assert_equal("Foo Goo Hoo","foo goo hoo".capitalize_words)
10
+ end
11
+
12
+
13
+ def test_words
14
+ assert_equal(['foo','goo','hoo'],"foo goo hoo".words)
15
+ end
16
+
17
+
18
+ def test_split_tab
19
+ assert_equal(['foo','goo','hoo'],"foo\tgoo\thoo".split_tab)
20
+ end
21
+
22
+
23
+ def test_split_tsv
24
+ assert_equal([['a','b','c'],['d','e','f'],['g','h','i']],"a\tb\tc\nd\te\tf\ng\th\ti".split_tsv)
25
+ end
26
+
27
+
28
+ def test_lowcase
29
+ assert_equal('foo_goo_hoo',"Foo GOO**_**Hoo".lowcase)
30
+ end
31
+
32
+
33
+ def test_to_class
34
+ assert_equal(String,'String'.to_class)
35
+ end
36
+
37
+
38
+ def test_to_class_nested
39
+ assert_equal(FooModule::FooClass,'FooModule::FooClass'.to_class)
40
+ end
41
+
42
+
43
+ def test_increment
44
+ assert_equal('5','4'.increment, 'number is entire string')
45
+ assert_equal('5foo','4foo'.increment, 'number is leftmost')
46
+ assert_equal('foo5','foo4'.increment, 'number is rightmost')
47
+ assert_equal('foo10','foo9'.increment, 'number is rightmost with carry')
48
+ assert_equal('foo5bar','foo4bar'.increment, 'number is in then middle')
49
+ assert_equal('foobar','foobar'.increment, 'no number, so should be unchanged')
50
+ end
51
+
52
+
53
+ def test_decrement
54
+ assert_equal('3','4'.decrement, 'number is entire string')
55
+ assert_equal('3foo','4foo'.decrement, 'number is leftmost')
56
+ assert_equal('foo3','foo4'.decrement, 'number is rightmost')
57
+ assert_equal('foo9','foo10'.decrement, 'number is rightmost with carry')
58
+ assert_equal('foo3bar','foo4bar'.decrement, 'number is in then middle')
59
+ assert_equal('foobar','foobar'.decrement, 'no number, so should be unchanged')
60
+ end
61
+
62
+
63
+ def test_prev_char
64
+ assert_equal(["-",false,false] ,String.prev_char("-")) #unchanged
65
+ assert_equal(["5",true,false] ,String.prev_char("6")) #numeric typical
66
+ assert_equal(["9",true,true] ,String.prev_char("0")) #numeric carry
67
+ assert_equal(["m",true,false] ,String.prev_char("n")) #lowercase typical
68
+ assert_equal(["z",true,true] ,String.prev_char("a")) #lowercase carry
69
+ assert_equal(["M",true,false] ,String.prev_char("N")) #uppercase typical
70
+ assert_equal(["Z",true,true] ,String.prev_char("A")) #uppercase carry
71
+ end
72
+
73
+
74
+ def test_prev
75
+ assert_equal('n-','n-'.prev) # unchanged
76
+ assert_equal('n5','n6'.prev) # numeric typical
77
+ assert_equal('m9','n0'.prev) # numeric carry
78
+ assert_equal('m999','n000'.prev) # numeric carries
79
+ assert_equal('ne','nf'.prev) # lowercase typical
80
+ assert_equal('mz','na'.prev) # lowercase carry
81
+ assert_equal('mzzz','naaa'.prev) # lowercase carries
82
+ assert_equal('NE','NF'.prev) # uppercase typical
83
+ assert_equal('MZ','NA'.prev) # uppercase carry
84
+ assert_equal('MZZZ','NAAA'.prev) # uppercase carries
85
+ end
86
+
87
+ def test_lorem_length
88
+ x = String.lorem_length
89
+ assert(x.is_a?(Integer),'x is integer')
90
+ assert(x>0,"x:#{x}>0")
91
+ assert(x<=20,"x:#{x}<=20")
92
+ end
93
+
94
+ def test_lorem
95
+ s = String.lorem
96
+ assert(s.is_a?(String),'s is string')
97
+ assert(s.size>0,"s.size:#{s.size}>0")
98
+ assert(s.size<20,"s.size:#{s.size}<=20")
99
+ end
100
+
101
+ def test_lorem_with_length
102
+ s = String.lorem(5)
103
+ assert(s.is_a?(String),'s is string')
104
+ assert(s.size==5,"s.size:#{s.size}==5")
105
+ end
106
+
107
+ end
108
+
109
+
110
+ # For testing #to_class
111
+ module FooModule #:nodoc: all
112
+ class FooClass
113
+ end
114
+ end
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
@@ -0,0 +1,26 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_ramp'
3
+
4
+
5
+ class SymbolTest < Test::Unit::TestCase
6
+
7
+
8
+ def test_comparable
9
+ assert_equal(-1,:foo<=>:goo)
10
+ assert_equal( 0,:foo<=>:foo)
11
+ assert_equal( 1,:goo<=>:foo)
12
+ end
13
+
14
+
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+