tagen 1.1.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.gitignore +4 -1
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG +6 -0
  4. data/Gemfile +2 -3
  5. data/Gemfile.lock +13 -15
  6. data/README.md +20 -39
  7. data/Rakefile +2 -1
  8. data/benchmark/a.rb +14 -0
  9. data/lib/tagen/core.rb +17 -22
  10. data/lib/tagen/core/array.rb +5 -109
  11. data/lib/tagen/core/array/append.rb +3 -0
  12. data/lib/tagen/core/array/delete_values.rb +43 -0
  13. data/lib/tagen/core/array/extract_options.rb +35 -94
  14. data/lib/tagen/core/class.rb +1 -0
  15. data/lib/tagen/core/enumerable.rb +15 -18
  16. data/lib/tagen/core/enumerator.rb +22 -12
  17. data/lib/tagen/core/exception.rb +5 -3
  18. data/lib/tagen/core/file.rb +1 -0
  19. data/lib/tagen/core/hash.rb +4 -39
  20. data/lib/tagen/core/integer.rb +2 -0
  21. data/lib/tagen/core/io.rb +59 -26
  22. data/lib/tagen/core/kernel.rb +5 -64
  23. data/lib/tagen/core/kernel/deprecate.rb +5 -0
  24. data/lib/tagen/core/kernel/platform.rb +46 -0
  25. data/lib/tagen/core/kernel/shell.rb +45 -0
  26. data/lib/tagen/core/module.rb +9 -11
  27. data/lib/tagen/core/numeric.rb +4 -2
  28. data/lib/tagen/core/object.rb +6 -21
  29. data/lib/tagen/core/process.rb +6 -4
  30. data/lib/tagen/core/re.rb +2 -2
  31. data/lib/tagen/core/string.rb +12 -47
  32. data/lib/tagen/core/time.rb +30 -38
  33. data/lib/tagen/erb.rb +10 -8
  34. data/lib/tagen/net/http.rb +33 -29
  35. data/lib/tagen/pathname.rb +1 -5
  36. data/lib/tagen/rbconfig.rb +8 -0
  37. data/lib/tagen/socket.rb +8 -2
  38. data/lib/tagen/uri.rb +9 -0
  39. data/lib/tagen/version.rb +1 -1
  40. data/lib/tagen/vim.rb +8 -8
  41. data/lib/tagen/xmpp4r.rb +23 -23
  42. data/spec/spec_helper.rb +23 -17
  43. data/spec/tagen/core/array/delete_values_spec.rb +19 -0
  44. data/spec/tagen/core/array/extract_options_spec.rb +9 -29
  45. data/spec/tagen/core/enumerable_spec.rb +9 -0
  46. data/spec/tagen/core/enumerator_spec.rb +10 -12
  47. data/spec/tagen/core/exception_spec.rb +14 -9
  48. data/spec/tagen/core/io_spec.rb +20 -0
  49. data/spec/tagen/core/kernel/platform_spec.rb +92 -0
  50. data/spec/tagen/core/kernel/shell_spec.rb +27 -0
  51. data/spec/tagen/core/numeric_spec.rb +10 -0
  52. data/spec/tagen/core/process_spec.rb +14 -0
  53. data/spec/tagen/core/re_spec.rb +9 -0
  54. data/spec/tagen/core/string_spec.rb +9 -0
  55. data/spec/tagen/core/time_spec.rb +6 -51
  56. data/spec/tagen/erb_spec.rb +3 -10
  57. data/spec/tagen/pathname_spec.rb +11 -0
  58. data/spec/tagen/rbconfig_spec.rb +11 -0
  59. data/spec/tagen/socket_spec.rb +7 -5
  60. data/spec/tagen/uri_spec.rb +13 -0
  61. data/tagen.gemspec +3 -4
  62. metadata +45 -51
  63. data/TODO +0 -1
  64. data/docs/Architecture.md +0 -17
  65. data/docs/CoreExtensions.md +0 -40
  66. data/docs/ExtraExtensions.md +0 -20
  67. data/lib/tagen/RMagick.rb +0 -12
  68. data/lib/tagen/audioinfo.rb +0 -22
  69. data/lib/tagen/cairo.rb +0 -811
  70. data/lib/tagen/core/extend_hash.rb +0 -46
  71. data/lib/tagen/core/marshal.rb +0 -34
  72. data/lib/tagen/core/open_option.rb +0 -161
  73. data/lib/tagen/core/string/pyformat.rb +0 -336
  74. data/lib/tagen/core/symbol.rb +0 -8
  75. data/lib/tagen/date.rb +0 -80
  76. data/lib/tagen/gdk_pixbuf2.rb +0 -26
  77. data/lib/tagen/gtk2.rb +0 -122
  78. data/lib/tagen/ncurses.rb +0 -246
  79. data/lib/tagen/poppler.rb +0 -48
  80. data/lib/tagen/tree.rb +0 -77
  81. data/lib/tagen/xmpp4r/roster.rb +0 -20
  82. data/lib/tagen/yaml.rb +0 -38
  83. data/spec/tagen/cairo_spec.rb +0 -137
  84. data/spec/tagen/core/array_spec.rb +0 -42
  85. data/spec/tagen/core/extend_hash_spec.rb +0 -54
  86. data/spec/tagen/core/hash_spec.rb +0 -10
  87. data/spec/tagen/core/module_spec.rb +0 -14
  88. data/spec/tagen/core/open_option_spec.rb +0 -83
  89. data/spec/tagen/core/string/pyformat_spec.rb +0 -98
  90. data/spec/tagen/core/symbol_spec.rb +0 -15
  91. data/spec/tagen/core_spec.rb +0 -6
  92. data/spec/tagen/date_spec.rb +0 -146
@@ -1,48 +0,0 @@
1
- require "poppler"
2
- =begin
3
- * **Install**: Ruby-Gnome
4
- =end
5
- module Poppler
6
-
7
- =begin
8
- Additional Method List
9
- ---------------------
10
- * \#npages: _alias from size_
11
- =end
12
- class Document
13
- alias npages size
14
- # get width height
15
- def wh; self[0].size end
16
- # get width
17
- def w; wh[0] end
18
- # get height
19
- def h; wh[1] end
20
- end # class Document
21
-
22
- =begin
23
- Additional Method List
24
- ----------------------
25
- * \#wh: _alias from size_
26
- =end
27
- class Page
28
- alias wh size
29
- # get width
30
- def w; size[0] end
31
- # get height
32
- def h; size[1] end
33
-
34
- # used when 'cairo' is installed
35
- #
36
- # @return [Cairo::Context]
37
- def cairo_context
38
- require "cairo"
39
- require_relative "cairo"
40
- surface = Cairo::ImageSurface.new(*self.wh)
41
- ctx = Cairo::Context.new(surface)
42
- render(ctx)
43
- ctx
44
- end # def cairo_context
45
-
46
- end # class Page
47
-
48
- end # module Poppler
@@ -1,77 +0,0 @@
1
- require "tree"
2
-
3
- =begin
4
- * **Install**: gem(rubytree)
5
- =end
6
- module Tree
7
- Fatal = Class.new Exception
8
- Error = Class.new Exception
9
- ENoNode = Class.new Error
10
-
11
- class TreeNode
12
-
13
- # get a Node name
14
- def get name
15
- return name if self.class===name
16
- treetage = Array===name ? name : name.split(/ +/)
17
-
18
- treetage.gach self.root do |n,i,m|
19
- if m[n]
20
- m[n]
21
- else
22
- raise ENoNode, "'#{n}` node doesn't exists for root `#{root.name}'"
23
- end
24
- end
25
- end
26
-
27
- # set a Node name
28
- def name= name
29
- old = @name
30
- @name = name
31
- children_hash = parent.instance_variable.get :@children_hash
32
- children_hash.delete old
33
- children_hash[@name] = self
34
- end
35
-
36
- alias original_parentage parentage
37
- # * default return nil for root
38
- # * now return [] for root
39
- def parentage
40
- is_root? ? [] : original_parentage
41
- end
42
-
43
- # parentage in reverse
44
- # @see parentage
45
- def treetage
46
- ([self.name] + self.parentage.map{|v| v.name}).reverse[1..-1]
47
- end
48
-
49
- # return "a b c"
50
- def treename
51
- self.treetage.join(" ")
52
- end
53
-
54
- def __compare other
55
- raise ArgumentError, "comparison '{self}` with '{other}` failed"
56
- .format(self.class, other) unless self.class === other
57
-
58
- a = self.treetage
59
- b = other.treetage
60
-
61
- if a.length==b.length
62
- return 0 if a==b
63
- elsif a.length < b.length
64
- return 1 if a==b[0...a.length]
65
- elsif a.length>b.length
66
- return -1 if a[0...b.length]==b
67
- end
68
- end
69
-
70
- # is same node ?
71
- def same?(other) __compare(other)==0 ? true : false end
72
- def ancestor_of?(other) __compare(other)==1 ? true : false end
73
- def descendant_of?(other) __compare(other)==-1 ? true : false end
74
- def ancestor_in?(other) [0, 1].include?(__compare(other)) ? true : false end
75
- def descendant_in?(other) [0,-1].include?(__compare(other)) ? true : false end
76
- end
77
- end
@@ -1,20 +0,0 @@
1
- =begin
2
- * **Install**: gem(xmpp4r)
3
- added:
4
- #unsubscribe
5
- =end
6
-
7
- module Jabber
8
- module Roster
9
- class Helper
10
- class RosterItem
11
-
12
- # unsubscribe an item
13
- def unsubscribe
14
- pres = Presence.new.set_type(:unsubscribe).set_to(jid.strip)
15
- @stream.send(pres)
16
- end
17
- end # class RosterItem
18
- end # Helper
19
- end # module Roster
20
- end # module Jabber
@@ -1,38 +0,0 @@
1
- require "yaml"
2
-
3
- =begin
4
- support #respond_to?(:path). e.g. Pa
5
-
6
- YAML.load(Pa('/tmp/a'))
7
- YAML.dump("x", Pa('/tmp/a'))
8
- =end
9
- module YAML
10
- class << self
11
- alias original_load load
12
- alias original_dump dump
13
-
14
- # add #path support
15
- # @param [String,IO,#path] path
16
- def load path
17
- if path.respond_to?(:path)
18
- path = path.path
19
- open(path){|f| original_load(f)}
20
-
21
- else
22
- original_load path
23
- end
24
- end
25
-
26
- # add String, #path support
27
- # @param [String,IO,#path] path
28
- def dump obj, path
29
- if path.respond_to?(:path)
30
- path = path.path
31
- open(path, "w+"){|f| original_dump(obj, f)}
32
- else
33
- original_dump obj, path
34
- end
35
- end
36
-
37
- end
38
- end
@@ -1,137 +0,0 @@
1
- =begin
2
- require "tagen/cairo"
3
-
4
- include Cairo
5
-
6
- tmpdir = Gile.dirname(__FILE__)+"/tmp"
7
- Gile.rmdir!(tmpdir)
8
- Gile.mkdir(tmpdir)
9
- Gile.chdir(tmpdir)
10
- #}}}1
11
- DEBUG[0] = true
12
-
13
- Test.skip do
14
- skip :table
15
- end
16
-
17
- class Test_Context < Test
18
- def test_du #{{{1
19
- # (x_str,nil) (nil,y_str) (x_str, y_str), (x,y)
20
- cr = Context.new(ImageSurface.new(200,200))
21
- cr.scale(2,4)
22
- cr.translate(10,10)
23
-
24
- assert_equal 1, cr.tdu(2)
25
- assert_equal 1, cr.tdu(nil, 4)
26
- assert_equal [1,1], cr.tdu(2,4)
27
- assert_equal [0,0], cr.du(20, 40)
28
- end # test_du
29
- #}}}1
30
- def test___pos #< du #{{{1
31
- cr = Context.new(ImageSurface.new(200,200))
32
- cr.translate(2,4)
33
- cr.scale(2,4)
34
- __pos = cr.method(:__pos)
35
-
36
- cr.xy 10,10
37
- assert_equal [0, 10], __pos.call(0, 10)
38
- assert_equal __pos.call(0, cr.du(nil,0)), __pos.call(0, :d0)
39
-
40
- cr.xy 10,10
41
- assert_equal [0, 20], __pos.call(0, "10")
42
- assert_equal [0, 10+cr.tdu(nil,10)], __pos.call(0, :r10)
43
- end
44
- #}}}1
45
- def test__angle #{{{1
46
- cr = Context.new(ImageSurface.new(200,200))
47
- __angle = cr.method(:__angle)
48
-
49
- assert_equal 10 , __angle.call("10")
50
- assert_equal [10, 10], __angle.call("10", "10")
51
- assert_equal [10*Math::PI/180.0, 10], __angle.call(10, "10")
52
- end
53
- #}}}1
54
- def test_bak #{{{1
55
- cr = Context.new(ImageSurface.new(200,200))
56
- # xy
57
- cr.xy 0,0
58
- cr.bak(:xy) do
59
- cr.xy 10,10
60
- end
61
- assert_equal [0,0], cr.xy
62
-
63
- # translate
64
- cr.translate(3,3)
65
- cr.bak(:translate) do
66
- cr.translate(10,10)
67
- end
68
- assert_equal [0,0], cr.du(3,3)
69
- cr.btranslate
70
-
71
- # scale
72
- cr.scale(2,4)
73
- cr.bak(:scale) do
74
- cr.scale(2,4)
75
- end
76
- assert_equal [1,1], cr.tdu(2, 4)
77
- cr.dscale 1,1
78
-
79
- # matrix
80
- cr.scale(2,4)
81
- cr.translate(10,10)
82
- cr.bak(:matrix) do
83
- cr.scale(2,4)
84
- cr.translate(10,10)
85
- end
86
- assert_equal [0,0], cr.du(20,40)
87
- assert_equal [1,1], cr.tdu(2,4)
88
- cr.dscale 1,1
89
- cr.btranslate
90
-
91
- # size
92
- cr.size=10
93
- cr.bak(:size) do
94
- cr.size=12
95
- end
96
- assert_equal 10, cr.size
97
-
98
- # all
99
- cr.size=10
100
- cr.xy 0,0
101
- cr.translate(3,3)
102
- cr.bak(:all) do
103
- cr.xy 10,10
104
- cr.translate(10,10)
105
- cr.size=12
106
- end
107
- assert_equal [0,0], cr.xy
108
- assert_equal [0,0], cr.du(3,3)
109
- assert_equal 10, cr.size
110
- end # def test_bak
111
- #}}}1
112
- def test_table #{{{1
113
- wh=[400,400]
114
- img = Cairo::ImageSurface.new(*wh)
115
- cr = Cairo::Context.new(img)
116
- cr.scale(*wh)
117
- cr.rectangle(0,0,1,1); cr.stroke
118
- cr.font= "iYahei"
119
- #============
120
-
121
- datas = [
122
- ["你好","tag"],
123
- ["你好","tag"],
124
- ]
125
-
126
- cr.dxy 20,20
127
- cr.table(datas[0], border:1)
128
- cr.dry 20
129
- cr.table(datas, border:1)
130
- #============
131
- img.write("a.png")
132
- `pic a.png`
133
- end
134
- #}}}1
135
- end
136
-
137
- =end
@@ -1,42 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Array do
4
- describe "#first!" do
5
- it "runs ok" do
6
- a = [0, 1, 2]
7
- a.first!(2).should == [0, 1]
8
- a.should == [2]
9
- end
10
- end
11
-
12
- describe "#last!" do
13
- it "runs ok" do
14
- a = [0, 1, 2]
15
- a.last!(2).should == [1, 2]
16
- a.should == [0]
17
- end
18
- end
19
-
20
- describe "#find!" do
21
- it "runs ok" do
22
- a = [0, 1, 2]
23
- a.find!{|v| v==1}.should == 1
24
- a.should == [0,2]
25
- end
26
- end
27
-
28
- describe "#find_all!" do
29
- it "runs ok" do
30
- a = [0, 1, 2]
31
- a.find_all!{|v| v==0 or v ==2}.should == [0,2]
32
- a.should == [1]
33
- end
34
- end
35
-
36
- #describe "#grep" do
37
- #it "supports array as an argument" do
38
- #a = [:a, :b, :c]
39
- #a.grep([:a, :b]).should == [:a, :b]
40
- #end
41
- #end
42
- end
@@ -1,54 +0,0 @@
1
- require "spec_helper"
2
- require "tagen/core/extend_hash"
3
-
4
- class ExtendHash
5
- class << self
6
- public :deep_convert
7
- end
8
- end
9
-
10
- describe ExtendHash do
11
- describe ".deep_convert" do
12
- it "convert string key to symbol key" do
13
- ExtendHash.deep_convert({"a" => 1, "b" => {"c" => 2}}).should == {a: 1, b: {c: 2}}
14
- end
15
- end
16
-
17
- describe ".[]" do
18
- it "convert Hash to ExtendHash with string key" do
19
- ret = ExtendHash[a: 1, "b" => 2]
20
- ret.should == {a: 1, b: 2}
21
- end
22
- end
23
-
24
- describe "#[]" do
25
- it "convert string-key to symbol-key" do
26
- h = ExtendHash.new
27
- h.store(:ok, 1)
28
- h["ok"].should == 1
29
- end
30
- end
31
-
32
- describe "#[]=" do
33
- it "convert string-key to symbol-key" do
34
- h = ExtendHash.new
35
- h["ok"] = 1
36
- h[:ok] = 1
37
- end
38
- end
39
-
40
- describe "#method_missing" do
41
- it "#key" do
42
- h = ExtendHash.new
43
- h[:ok] = 1
44
- h.ok.should == 1
45
- end
46
-
47
- it "#key=" do
48
- h = ExtendHash.new
49
- h.ok = 1
50
- h.ok.should == 1
51
- end
52
- end
53
- end
54
-
@@ -1,10 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Hash do
4
- #describe "#grep" do
5
- # it "works" do
6
- # a = {a: 1, b: 2, c: 3}
7
- # a.grep([:a, :b]).should == {a: 1, b: 2}
8
- # end
9
- #end
10
- end
@@ -1,14 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Module do
4
- describe "#consts" do
5
- it "runs ok" do
6
- module Constants
7
- A = 1
8
- end
9
-
10
- Constants.consts.should == {A: 1}
11
-
12
- end
13
- end
14
- end