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,21 +1,6 @@
1
- class Object
2
- # default \#dup is shallow.
3
- #
4
- # @example
5
- # # dup
6
- # a={a: { b: 1 }}
7
- # a2 = a.dup
8
- # a2[:a][:b] = 2
9
- # p a #=> {a: {b: 2} }
10
- #
11
- # # use deepdup
12
- # a= {a: {b: 1 }}
13
- # a2 = a.deepdup
14
- # a2[:a][:b] = 2
15
- # p a #=> {a: {b: 1}}
16
- #
17
- # @return [Object]
18
- def deepdup
19
- Marshal.load(Marshal.dump(self))
20
- end
21
- end
1
+ require "active_support/core_ext/object/blank"
2
+ require "active_support/core_ext/object/inclusion"
3
+ require "active_support/core_ext/object/try"
4
+ #require "active_support/core_ext/object/deep_dup"
5
+ require "active_support/core_ext/object/instance_variables"
6
+ require "active_support/core_ext/object/duplicable"
@@ -1,11 +1,13 @@
1
+ require "tagen/core/kernel/platform"
2
+
1
3
  module Process
2
- # check if the pid's process is running.
3
- #
4
+ # Check if the pid's process is running.
4
5
  # @note for linux only
5
- # @param [String, Integer] pid process id
6
+ #
7
+ # @param [Integer] pid process id
6
8
  # @return [Boolean]
7
9
  def self.exists?(pid)
8
- raise NotImplementError unless linux?
10
+ raise NotImplementedError unless linux?
9
11
  File.exists?("/proc/#{pid}")
10
12
  end
11
13
  end
@@ -1,8 +1,8 @@
1
1
  class MatchData
2
- # group-name regexp
2
+ # Returns a hash of named group matches.
3
+ #
3
4
  # @return [Hash] {:name => "mathed-data"}
4
5
  def to_hash
5
6
  Hash[names.map(&:to_sym).zip(captures)]
6
7
  end
7
8
  end
8
-
@@ -1,48 +1,13 @@
1
- class String
2
- @@didits = "0123456789"
3
- @@hexdigits = "01234567890ABCDEF"
4
- @@octdigits = "01234567"
5
- @@uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
6
- @@lowercase = "abcdefghijklmnopqrstuvwxyz"
7
- @@letters = @@uppercase + @@lowercase
8
-
9
- class << self
10
-
11
- # "0123456789"
12
- #
13
- # @return [String]
14
- def digits; @@digits end
15
-
16
- # "01234567890ABCDEF"
17
- #
18
- # @return [String]
19
- def hexdigits; @@hexdigits end
20
-
21
- # "01234567"
22
- #
23
- # @return [String]
24
- def octdigits; @@octdigits end
25
-
26
- # "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
27
- #
28
- # @return [String]
29
- def uppercase; @@uppercase end
30
-
31
- # "abcdefghijklmnopqrstuvwxyz"
32
- #
33
- # @return [String]
34
- def lowercase; @@lowercase end
35
-
36
- # "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
37
- #
38
- # @return [String]
39
- def letters; @@letters end
40
- end
41
-
42
- # return ascii code
1
+ class String
2
+ # Return first character's ascii code.
3
+ #
43
4
  # @example
44
- # 'a'.ascii #=> 97
45
- def ascii() bytes.first end
46
- end # class String
47
-
48
- require_relative "string/pyformat"
5
+ #
6
+ # 'a'.ascii -> 97
7
+ #
8
+ def ascii()
9
+ bytes.first
10
+ end
11
+ end
12
+
13
+ require "active_support/core_ext/string"
@@ -1,50 +1,42 @@
1
1
  class Time
2
- # return a float of time since linux epoch
2
+ # Return a float of time since linux epoch
3
3
  #
4
- # #=> 1295953427.0005338
4
+ # @example
5
+ #
6
+ # Time.time -> 1295953427.0005338
5
7
  #
6
8
  # @return [Float]
7
9
  def self.time
8
10
  now.to_f
9
11
  end
12
+ end
10
13
 
11
- class Deta
12
- class <<self
13
- # @param [Time] from
14
- # @param [Time] to
15
- # @return [Time::Deta] deta
16
- def deta(from, to)
17
- seconds = (from-to).to_i
18
- self.new(seconds)
19
- end
20
- end
21
-
22
- attr_reader :years, :months, :days, :hours, :minutes, :seconds
23
-
24
- def initialize(seconds)
25
- deta = seconds
26
- deta, @seconds = deta.divmod(60)
27
- deta, @minutes = deta.divmod(60)
28
- deta, @hours = deta.divmod(24)
29
- deta, @days = deta.divmod(30)
30
- @years, @months = deta.divmod(12)
31
- end
32
-
33
- def display(include_seconds=true)
34
- ret = ""
35
- ret << "#{years} years " unless years == 0
36
- ret << "#{months} months " unless months == 0
37
- ret << "#{days} days " unless days==0
38
- ret << "#{hours} hours " unless hours == 0
39
- ret << "#{minutes} minutes " unless minutes == 0
40
- ret << "#{seconds} seconds" if include_seconds
14
+ class Numeric
15
+ # Reports the approximate distance in time between two Time, Date or DateTime objects or integers as seconds.
16
+ #
17
+ # @example
18
+ #
19
+ # 1.time_humanize(true) -> 1 seconds
20
+ # 36561906.time_humanize -> 1 years 2 months 3 days 4 hours 5 minutes
21
+ #
22
+ def time_humanize(include_seconds=false)
23
+ deta = self
24
+ deta, seconds = deta.divmod(60)
25
+ deta, minutes = deta.divmod(60)
26
+ deta, hours = deta.divmod(24)
27
+ deta, days = deta.divmod(30)
28
+ years, months = deta.divmod(12)
41
29
 
42
- ret
43
- end
30
+ ret = ""
31
+ ret << "#{years} years " unless years == 0
32
+ ret << "#{months} months " unless months == 0
33
+ ret << "#{days} days " unless days == 0
34
+ ret << "#{hours} hours " unless hours == 0
35
+ ret << "#{minutes} minutes " unless minutes == 0
36
+ ret << "#{seconds} seconds" if include_seconds
44
37
 
45
- # to [years, months, days, hours minutes seconds]
46
- def to_a
47
- [ years, months, days, hours, minutes, seconds ]
48
- end
38
+ ret.rstrip
49
39
  end
50
40
  end
41
+
42
+ require "active_support/time"
@@ -1,25 +1,28 @@
1
- require 'erb'
1
+ require "erb"
2
2
 
3
3
  class ERB
4
- alias original_result result
5
-
6
4
  # add locals support
5
+ #
6
+ # @param [Hash,OpenOption] locals
7
7
  #
8
8
  # @example
9
+ #
9
10
  # erb = Erb.new("<%=a%>")
10
11
  # erb.result(nil, a: 1) #=> "1"
11
12
  #
12
- # @param [Hash,OpenOption] locals
13
- def result(bind=nil, locals={})
13
+ def result_with_tagen(bind=nil, locals={})
14
14
  bind ||= TOPLEVEL_BINDING
15
15
  if locals.empty?
16
- original_result bind
16
+ result_without_tagen bind
17
17
  else
18
18
  result_with_locals bind, locals
19
19
  end
20
20
  end
21
21
 
22
- private
22
+ alias result_without_tagen result
23
+ alias result result_with_tagen
24
+
25
+ private
23
26
  def result_with_locals(bind, locals)
24
27
  @locals = locals
25
28
  evalstr = <<-EOF
@@ -32,5 +35,4 @@ end
32
35
  eval evalstr
33
36
  run_erb
34
37
  end
35
-
36
38
  end
@@ -1,34 +1,38 @@
1
+ require "net/http"
2
+
1
3
  module Net
2
- class HTTP
3
- class << self
4
+ class HTTP
5
+ class << self
4
6
 
5
- # support params
6
- #
7
- # @example
8
- # get1("http://www.google.com/search", "&q=foo")
9
- # get1("http://www.google.com/search", {"q" => "foo"} )
10
- #
11
- # @param [String Hash] params Hash by URI.encoding_www_form
12
- def get1 path, params, initheader={}, &blk
13
- path = path + "?" + (String===params ? params : URI.encode_www_form(params))
14
- req = Get.new(path, initheader)
15
- request req, &blk
16
- end
7
+ # support params
8
+ #
9
+ # @param [String Hash] params Hash by URI.encoding_www_form
10
+ #
11
+ # @example
12
+ #
13
+ # get1("http://www.google.com/search", "&q=foo")
14
+ # get1("http://www.google.com/search", {"q" => "foo"} )
15
+ #
16
+ def get1 path, params, initheader={}, &blk
17
+ path = path + "?" + (String===params ? params : URI.encode_www_form(params))
18
+ req = Get.new(path, initheader)
19
+ request req, &blk
20
+ end
17
21
 
18
- # support params
19
- #
20
- # @see get1
21
- def post1 path, params, initheader={}, &blk
22
- req = Post.new(path, initheader)
23
- if String===params
24
- req.body = params
25
- req.content_type = 'application/x-www-form-urlencoded'
26
- else
27
- req.set_form_data(params)
28
- end
29
- request req, &blk
30
- end
22
+ # support params
23
+ #
24
+ # @see get1
25
+ def post1 path, params, initheader={}, &blk
26
+ req = Post.new(path, initheader)
27
+ if String===params
28
+ req.body = params
29
+ req.content_type = 'application/x-www-form-urlencoded'
30
+ else
31
+ req.set_form_data(params)
32
+ end
33
+ request req, &blk
34
+ end
31
35
 
32
- end
33
- end
36
+ end
37
+ end
34
38
  end
@@ -1,9 +1,5 @@
1
1
  require "pathname"
2
- =begin
3
- Additional Methods List
4
- -----------------------
5
- * \#path _alias from to\_s_
6
- =end
2
+
7
3
  class Pathname
8
4
  alias path to_s
9
5
  end
@@ -0,0 +1,8 @@
1
+ require "rbconfig"
2
+
3
+ module RbConfig
4
+ # short-cut method to CONFIG#[]
5
+ def self.[](key)
6
+ CONFIG[key]
7
+ end
8
+ end
@@ -63,18 +63,24 @@ class Socket
63
63
  # pack human-readable address to Socket address
64
64
  #
65
65
  # @example
66
+ #
66
67
  # addr("192.168.1.1") #=> "\xC0\xA8\x01\x01"
67
68
  #
68
69
  # @return [String] address used by Socket
69
70
  # @see unaddr
70
- def addr(str) str.split(".").map{|v|v.to_i}.pack("CCCC") end
71
+ def addr(str)
72
+ str.split(".").map{|v|v.to_i}.pack("CCCC")
73
+ end
71
74
 
72
75
  # unpack to humna-readable address from Socket address
73
76
  #
74
77
  # @example
78
+ #
75
79
  # unaddr("\xC0\xA8\x01\x01") #=> "192.168.1.1"
76
80
  #
77
81
  # @return [String] human readable address
78
- def unaddr(str) str.unpack("CCCC").join(".") end
82
+ def unaddr(str)
83
+ str.unpack("CCCC").join(".")
84
+ end
79
85
  end
80
86
  end
@@ -0,0 +1,9 @@
1
+ require "uri"
2
+
3
+ class URI::Generic
4
+ def to_hash
5
+ component.each.with_object({}) {|k, m|
6
+ m[k] = send(k)
7
+ }
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Tagen
2
- VERSION = "1.1.7"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,12 +1,12 @@
1
- =begin
2
- used by VimL(Vim Script)
3
- =end
1
+ # used by VimL(Vim Script)
2
+ #
4
3
 
5
- # in vim
6
- # print "guten" => guten\n
7
- # print "guten\ntag" => guten\n
8
- # each_str.split("\n")
9
- def vimprint *args
4
+ # @example
5
+ #
6
+ # vimprint "guten" -> guten\n
7
+ # vimprint "guten\ntag" -> guten\n
8
+ #
9
+ def vimprint(*args)
10
10
  args.each do |arg|
11
11
  arg = arg.to_s
12
12
  arg.split("\n").each {|v| print v}
@@ -1,35 +1,35 @@
1
1
  require "xmpp4r"
2
- require "tagen/xmpp4r/roster"
3
2
 
4
- # patch for https://github.com/ln/xmpp4r/issues/3#issuecomment-1739952
3
+ # bugfix. support UTF-8
4
+ # patch from https://github.com/ln/xmpp4r/issues/3#issuecomment-1739952
5
5
 
6
6
  if RUBY_VERSION < "1.9"
7
7
  # ...
8
8
  else
9
- # Encoding patch
10
- require 'socket'
11
- class TCPSocket
12
- def external_encoding
13
- Encoding::BINARY
14
- end
9
+ # Encoding patch
10
+ require 'socket'
11
+ class TCPSocket
12
+ def external_encoding
13
+ Encoding::BINARY
15
14
  end
15
+ end
16
16
 
17
- require 'rexml/source'
18
- class REXML::IOSource
19
- alias_method :encoding_assign, :encoding=
20
- def encoding=(value)
21
- encoding_assign(value) if value
22
- end
17
+ require 'rexml/source'
18
+ class REXML::IOSource
19
+ alias_method :encoding_assign, :encoding=
20
+ def encoding=(value)
21
+ encoding_assign(value) if value
23
22
  end
23
+ end
24
24
 
25
- begin
26
- # OpenSSL is optional and can be missing
27
- require 'openssl'
28
- class OpenSSL::SSL::SSLSocket
29
- def external_encoding
30
- Encoding::BINARY
31
- end
32
- end
33
- rescue
25
+ begin
26
+ # OpenSSL is optional and can be missing
27
+ require 'openssl'
28
+ class OpenSSL::SSL::SSLSocket
29
+ def external_encoding
30
+ Encoding::BINARY
31
+ end
34
32
  end
33
+ rescue
34
+ end
35
35
  end