tagen 1.1.7 → 2.0.0

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.
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,8 +0,0 @@
1
- class Symbol
2
- # confict with active_support/core
3
- # goes to String, return Symbol
4
- #def method_missing name, *args
5
- #ret = to_s.send name, *args
6
- #String===ret ? ret.to_sym : ret
7
- #end
8
- end
@@ -1,80 +0,0 @@
1
- require "date"
2
-
3
- class Date # ::Deta
4
- class Deta
5
- class <<self
6
- # @param [Date] from
7
- # @param [Date] to
8
- # @return [Date::Deta] deta
9
- def deta(from, to)
10
- days = (from-to).to_i
11
- self.new(days)
12
- end
13
- end
14
-
15
- attr_reader :years, :months, :days
16
-
17
- def initialize(days)
18
- deta = days
19
- deta, @days = deta.divmod(30)
20
- @years, @months = deta.divmod(12)
21
- end
22
-
23
- def display(include_days=true)
24
- ret = ""
25
- ret << "#{years} years " unless years == 0
26
- ret << "#{months} months " unless months == 0
27
- ret << "#{days} days" unless (!include_days && days==0)
28
-
29
- ret
30
- end
31
-
32
- # to [years months days]
33
- def to_a
34
- [ years, months, days ]
35
- end
36
- end
37
- end
38
-
39
-
40
- class DateTime # ::Deta
41
- class Deta
42
- class <<self
43
- # @param [DateTime] from
44
- # @param [DateTime] to
45
- # @return [DateTime::Deta] deta
46
- def deta(from, to)
47
- seconds = (from-to)*24*3600.to_i
48
- self.new(seconds)
49
- end
50
- end
51
-
52
- attr_reader :years, :months, :days, :hours, :minutes, :seconds
53
-
54
- def initialize(seconds)
55
- deta = seconds
56
- deta, @seconds = deta.divmod(60)
57
- deta, @minutes = deta.divmod(60)
58
- deta, @hours = deta.divmod(24)
59
- deta, @days = deta.divmod(30)
60
- @years, @months = deta.divmod(12)
61
- end
62
-
63
- def display(include_seconds=true)
64
- ret = ""
65
- ret << "#{years} years " unless years == 0
66
- ret << "#{months} months " unless months == 0
67
- ret << "#{days} days " unless days==0
68
- ret << "#{hours} hours " unless hours == 0
69
- ret << "#{minutes} minutes " unless minutes == 0
70
- ret << "#{seconds} seconds" if include_seconds
71
-
72
- ret
73
- end
74
-
75
- # to [years, months, days, hours, minutes, seconds]
76
- def to_a
77
- [ years, months, days, hours, minutes, seconds ]
78
- end
79
- end
80
- end
@@ -1,26 +0,0 @@
1
- module Gdk
2
- class Pixbuf
3
- # get width, height
4
- #
5
- # @return [Array] [width, height]
6
- def wh; [width.to_f, height.to_f] end
7
-
8
- # get width
9
- #
10
- # @return [Float] width
11
- def w; wh[0] end
12
-
13
- # get height
14
- #
15
- # @return [Float] height
16
- def h; wh[1] end
17
-
18
- # set width, height
19
- #
20
- # @param [Array] wh [width, height]
21
- def wh=(wh) width=wh[0]; height=wh[1] end
22
-
23
- alias w= width=
24
- alias h= height=
25
- end
26
- end
@@ -1,122 +0,0 @@
1
- require "cairo"
2
- require_relative "cairo"
3
- require "gtkhtml2"
4
-
5
- module Gtk
6
-
7
- class Window
8
- # alias from set_default_size
9
- def default_size=(wh)
10
- set_default_size(*wh)
11
- end
12
- end # class Window
13
-
14
- class ListStore
15
- alias append_ append
16
- # @example
17
- # data=[
18
- # [1, 2],
19
- # [3, 4]
20
- # ]
21
- # liststore.append(data)
22
- def append rows
23
- rows.each do |row|
24
- iter = append_
25
- row.each do |col, col_i|
26
- iter[col_i] = col
27
- end
28
- end
29
- end
30
- end # class ListStore
31
-
32
- =begin
33
- Addition Methods list
34
- ---------------------
35
- * \#add _alias from add\_widget_
36
- =end
37
- class SizeGroup
38
- alias initialize_ initialize
39
- # add mode=HORIZONTAL as default option
40
- def _initialize(mode=HORIZONTAL)
41
- initialize_(mode)
42
- end
43
- alias add add_widget
44
- end # class SizeGroup
45
-
46
- class PrintOperation
47
- alias initialize_ initialize
48
- # add @ispreview instance variable
49
- def initialize
50
- initialize_
51
-
52
- @ispreview = false
53
- signal_connect("ready") do |previewop, ctx|
54
- @ispreview = true
55
- end
56
- end
57
-
58
- def preview?; @ispreview end
59
-
60
- alias run_ run
61
- def run(action=:print_dialog, parent=nil, &blk)
62
- action = PrintOperation.const_get("ACTION_#{action}".upcase)
63
- if blk
64
- run_(action, parent){|result|
65
- blk.call self,result.nick.gsub(/-/, "_").to_sym
66
- }
67
- else
68
- run_(action, parent)
69
- end
70
- end # def run
71
-
72
- alias status_ status
73
- # return symbol.
74
- def status
75
- status_.nick.gsub(/-/,"_").to_sym
76
- end # def status
77
-
78
- end # class PrintOperation
79
-
80
- class Entry
81
- alias text_ text
82
-
83
- # default encoding is ASCII-8BIT, some error occurs.
84
- # change to text.force_encoding("UTF-8")
85
- def text
86
- text_.force_encoding "UTF-8"
87
- end
88
- end
89
-
90
- end # module Gtk
91
-
92
- module Gdk
93
-
94
- class EventKey
95
- # return {Gdk::Key} instance
96
- def key
97
- Key.new keyval
98
- end
99
-
100
- end # class EventKey
101
-
102
- class Key
103
- attr_reader :code, :name
104
- def initialize keyval
105
- @code = keyval
106
- @name = Keyval.to_name(keyval).downcase.to_sym
107
- end
108
-
109
- def ==(key)
110
- case key
111
- when Integer
112
- @code == key
113
- when String,Symbol
114
- @name == key.to_sym
115
- end
116
- end # def ==
117
-
118
- def inspect; @name end
119
-
120
- end # class Key
121
- end # module Gdk
122
-
@@ -1,246 +0,0 @@
1
- require "ncurses"
2
- =begin
3
-
4
- Ncurses
5
- @stdscr @curscr @newscr
6
- @windows_hash
7
- .
8
- move(y,x) #stdscr
9
- wmove(win, y,x)
10
-
11
- == extensions
12
-
13
- class MEVENT; end
14
-
15
- class SCREEN; end
16
-
17
- module Panel
18
- class PANEL; end
19
- end
20
-
21
- module Form
22
- class FORM; end
23
- class FIELD; end
24
- class FIELDTYPE; end
25
- end
26
-
27
- module Menu
28
- class MENU; end
29
- class ITEM; end
30
- end
31
-
32
- =end
33
-
34
- =begin
35
- * **Install**: gem(rbcurse)
36
- =end
37
- module Ncurses
38
-
39
- # a convient function.
40
- #
41
- # setup initscr cbreak nonl noecho
42
- #
43
- # @example
44
- # new do |stdsrc|
45
- # ..
46
- # end
47
- #
48
- def self.new &blk
49
- begin
50
- initscr
51
- cbreak
52
- nonl
53
- noecho
54
-
55
- stdscr.intrflush(false)
56
- stdscr.keypad(true)
57
-
58
- blk.call stdscr if blk
59
- ensure
60
- self.end if blk
61
- end
62
- stdscr
63
- end
64
-
65
- # end ncurses
66
- #
67
- # call echo nocbreak nl endwin
68
- #
69
- # @see self.new
70
- def self.end
71
- echo
72
- nocbreak
73
- nl
74
- endwin
75
- end
76
-
77
- end # module Ncurses
78
-
79
- module Ncurses # Key
80
- class Key
81
- include Comparable
82
- @@keys = {}
83
- keys = String.letters.to_a + String.digits.to_a + \
84
- %w(` ~ ! @ # $ % ^ & * ( ) - _ = + \ | [ ] { } : " ' ; < . > / ? ,)
85
- keys.each do |v|
86
- @@keys[v] = v.ascii
87
- end
88
- @@codes = @@keys.invert
89
-
90
- attr_reader :key, :code
91
-
92
- def initialize(arg)
93
- # arg: int or str
94
- if arg.class == Fixnum
95
- @code = arg
96
- @key = @@codes[arg]
97
- elsif arg.class == String
98
- @key = arg
99
- @code = @@keys[arg]
100
- end
101
- end
102
-
103
- def keys; @@keys end
104
- def codes; @@codes end
105
-
106
- def <=>(arg)
107
- if arg.class == self.class
108
- code <=> arg.code
109
- elsif arg.class == Fixnum
110
- code <=> arg
111
- elsif arg.class == String
112
- code <=> @@keys[arg]
113
- end
114
- end
115
-
116
- def to_s; "#{@key}: #{@code}" end
117
-
118
- end # class Key
119
- end
120
-
121
- module Ncurses # WINDOW
122
- class WINDOW
123
- def initialize
124
- @stdscr = Ncurses.stdscr
125
- @curscr = Ncurses.curscr
126
- end
127
-
128
- # xy mvxy wh ..
129
- def xy
130
- y,x=[],[]
131
- Ncurses.getyx(self,y,x)
132
- [x[0], y[0]]
133
- end
134
- def x; xy[0] end
135
- def y; xy[1] end
136
-
137
- def save; @save_xy = xy end
138
- def restore; xy *@save_xy end
139
-
140
- def mvxy x,y, &blk
141
- x,y = convert_xy(x,y)
142
- x_, y_ = self.xy
143
- Ncurses.move(y,x)
144
- if blk
145
- blk.call
146
- Ncurses.move(y_, x_)
147
- end
148
- end
149
-
150
- def mvx x, &blk; mvxy(x, self.y) end
151
- def mvy y, &blk; mvxy(self.x, y) end
152
-
153
- def rmvxy x,y, &blk; mvxy(x.to_s, y.to_s, &blk) end
154
- def rmvx x, &blk; mvx(x.to_s, &blk) end
155
- def rmvy y, &blk; mvy(y.to_s, &blk) end
156
-
157
- def wh
158
- y,x=[],[]
159
- Ncurses.getmaxyx(self,y,x)
160
- [x, y]
161
- end
162
- def w; wh[0] end
163
- def h; wh[1] end
164
-
165
- def beginxy
166
- y,x=[],[]
167
- Ncurses.getbegyx(self,y,x)
168
- [x,y]
169
- end
170
- def beginx; beginxy[0] end
171
- def beginy; beginxy[1] end
172
-
173
- def convert_xy x=nil,y=nil
174
- x = self.x+x.to_i if x and String===x
175
- y = self.y+y.to_i if y and String===y
176
-
177
- if x and y
178
- [x,y]
179
- elsif x
180
- x
181
- elsif y
182
- y
183
- end
184
- end
185
-
186
- # getc
187
- # ctrl_a "\C-a"
188
- # alt_a "\ea"
189
- # ctrl_alt_a "\e\C-a"
190
- # KEYS #{{{2
191
- keys = {}
192
- Ncurses.constants.grep(/^KEY_/).each do |const|
193
- value = Ncurses.get_const const
194
- key = const[/^KEY_(.*)/, 1]
195
- keys[value] = key.downcase.to_sym
196
- end
197
- keys += {
198
- 127 => :backspace,
199
- [27, 127] => :alt_backspace,
200
-
201
- 289 => :ctrl_f1, # :f25
202
- 290 => :ctrl_f2,
203
- 291 => :ctrl_f3,
204
- 292 => :ctrl_f4,
205
- 293 => :ctrl_f5,
206
- 294 => :ctrl_f6,
207
- 295 => :ctrl_f7,
208
- 296 => :ctrl_f8,
209
- 297 => :ctrl_f9,
210
- 298 => :ctrl_f1,
211
- 299 => :ctrl_f11,
212
- 300 => :ctrl_f12,
213
-
214
- 313 => :alt_f1,
215
- 314 => :alt_f2,
216
- 315 => :alt_f3,
217
- 316 => :alt_f4,
218
- 317 => :alt_f5,
219
- 318 => :alt_f6,
220
- 319 => :alt_f7,
221
- 320 => :alt_f8,
222
- 321 => :alt_f9,
223
- 322 => :alt_f10,
224
- 323 => :alt_f11,
225
- 324 => :alt_f12,
226
- }
227
- KEYS = keys
228
-
229
- def getc
230
- key = getch
231
- if key==27
232
- c = getch
233
- (value=KEYS[[27, c]]) ? value : "\e"+c.chr
234
- elsif value=KEYS[key]
235
- value
236
- else
237
- # a "\C-a"
238
- key.chr
239
- end
240
- end
241
-
242
- def necho(*args); Ncurses.addstr(args.gach{|v|v.to_s}.join(" ")) end
243
- def echo *args; necho *args, "\n" end
244
-
245
- end # class WINDOW
246
- end