libaaron 1.0.1 → 1.0.2
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.
- data/lib/libaaron.rb +113 -0
- data/libaaron.rb +2 -113
- metadata +3 -2
data/lib/libaaron.rb
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Version 1.0
|
|
4
|
+
|
|
5
|
+
# Copyright 2008, 2009, 2010 Aaron Lynch
|
|
6
|
+
|
|
7
|
+
=begin
|
|
8
|
+
This library is free software: you can redistribute it and/or modify
|
|
9
|
+
it under the terms of the GNU General Public License as published by
|
|
10
|
+
the Free Software Foundation, either version 2 of the License, or
|
|
11
|
+
(at your option) any later version.
|
|
12
|
+
|
|
13
|
+
This library is distributed in the hope that it will be useful,
|
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
GNU General Public License for more details.
|
|
17
|
+
|
|
18
|
+
You should have received a copy of the GNU General Public License
|
|
19
|
+
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
=end
|
|
21
|
+
|
|
22
|
+
class Dir
|
|
23
|
+
def self.real_entries(directory=".")
|
|
24
|
+
entries(directory)-[".",".."]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class Regexp
|
|
29
|
+
def multi_match(match_string)
|
|
30
|
+
matches = Array.new
|
|
31
|
+
while match = self.match(match_string)
|
|
32
|
+
matches << match
|
|
33
|
+
match_string = match.post_match
|
|
34
|
+
yield match if block_given?
|
|
35
|
+
end
|
|
36
|
+
return matches
|
|
37
|
+
end
|
|
38
|
+
def multi_match_inside_wrapper(wrapper_pattern, string, &block)
|
|
39
|
+
wrapper_pattern.multi_match(string) do |match|
|
|
40
|
+
if block.nil?
|
|
41
|
+
return self.multi_match(match[1])
|
|
42
|
+
else
|
|
43
|
+
self.multi_match(match[1], &block)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class Object
|
|
50
|
+
def unique_methods
|
|
51
|
+
return self.methods-Object.methods
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class Hash
|
|
56
|
+
def increment(index, quantity = 1)
|
|
57
|
+
if self[index]
|
|
58
|
+
self[index] += quantity
|
|
59
|
+
else
|
|
60
|
+
self[index] = quantity
|
|
61
|
+
end
|
|
62
|
+
return self[index]
|
|
63
|
+
end
|
|
64
|
+
def decrement(index, quantity = 1)
|
|
65
|
+
increment(index, -quantity)
|
|
66
|
+
end
|
|
67
|
+
def sort(&block)
|
|
68
|
+
block = Proc.new {|a,b| a[1] <=> b[1]} if block.nil?
|
|
69
|
+
super(&block)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class Array
|
|
74
|
+
def total
|
|
75
|
+
self.inject {|sum,num| sum+num}
|
|
76
|
+
end
|
|
77
|
+
def to_hash
|
|
78
|
+
out_hash = Hash.new
|
|
79
|
+
for pair in self
|
|
80
|
+
raise "Malformed array" unless pair.is_a?(Array) && (pair.length == 2)
|
|
81
|
+
out_hash[pair[0]] = pair[1]
|
|
82
|
+
end
|
|
83
|
+
return out_hash
|
|
84
|
+
end
|
|
85
|
+
alias to_h to_hash
|
|
86
|
+
alias to_hsh to_hash
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class Numeric
|
|
90
|
+
#Taken from a code snippet by tthorley at http://codesnippets.joyent.com/posts/show/1812
|
|
91
|
+
def self.format(number, value_separator = ",", trailing_zeroes = 2, after = 3, decimal_separator = ".")
|
|
92
|
+
pre,post = number.to_s.split(".")
|
|
93
|
+
pre.gsub(/(\d)(?=(\d{#{after}})+$)/, '\0' + value_separator)+(post ? "#{decimal_separator}#{post == "0" ? "0"*trailing_zeroes : post}" : "")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class Struct
|
|
98
|
+
def to_hash
|
|
99
|
+
hash = Hash.new
|
|
100
|
+
for key in self.members
|
|
101
|
+
hash[key] = self[key]
|
|
102
|
+
end
|
|
103
|
+
return hash
|
|
104
|
+
end
|
|
105
|
+
alias to_h to_hash
|
|
106
|
+
alias to_hsh to_hash
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
module Kernel
|
|
110
|
+
def numform(*args)
|
|
111
|
+
Numeric.format(*args)
|
|
112
|
+
end
|
|
113
|
+
end
|
data/libaaron.rb
CHANGED
|
@@ -1,113 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
# Version 1.0
|
|
4
|
-
|
|
5
|
-
# Copyright 2008, 2009, 2010 Aaron Lynch
|
|
6
|
-
|
|
7
|
-
=begin
|
|
8
|
-
This library is free software: you can redistribute it and/or modify
|
|
9
|
-
it under the terms of the GNU General Public License as published by
|
|
10
|
-
the Free Software Foundation, either version 2 of the License, or
|
|
11
|
-
(at your option) any later version.
|
|
12
|
-
|
|
13
|
-
This library is distributed in the hope that it will be useful,
|
|
14
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
GNU General Public License for more details.
|
|
17
|
-
|
|
18
|
-
You should have received a copy of the GNU General Public License
|
|
19
|
-
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
=end
|
|
21
|
-
|
|
22
|
-
class Dir
|
|
23
|
-
def self.real_entries(directory=".")
|
|
24
|
-
entries(directory)-[".",".."]
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
class Regexp
|
|
29
|
-
def multi_match(match_string)
|
|
30
|
-
matches = Array.new
|
|
31
|
-
while match = self.match(match_string)
|
|
32
|
-
matches << match
|
|
33
|
-
match_string = match.post_match
|
|
34
|
-
yield match if block_given?
|
|
35
|
-
end
|
|
36
|
-
return matches
|
|
37
|
-
end
|
|
38
|
-
def multi_match_inside_wrapper(wrapper_pattern, string, &block)
|
|
39
|
-
wrapper_pattern.multi_match(string) do |match|
|
|
40
|
-
if block.nil?
|
|
41
|
-
return self.multi_match(match[1])
|
|
42
|
-
else
|
|
43
|
-
self.multi_match(match[1], &block)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
class Object
|
|
50
|
-
def unique_methods
|
|
51
|
-
return self.methods-Object.methods
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
class Hash
|
|
56
|
-
def increment(index, quantity = 1)
|
|
57
|
-
if self[index]
|
|
58
|
-
self[index] += quantity
|
|
59
|
-
else
|
|
60
|
-
self[index] = quantity
|
|
61
|
-
end
|
|
62
|
-
return self[index]
|
|
63
|
-
end
|
|
64
|
-
def decrement(index, quantity = 1)
|
|
65
|
-
increment(index, -quantity)
|
|
66
|
-
end
|
|
67
|
-
def sort(&block)
|
|
68
|
-
block = Proc.new {|a,b| a[1] <=> b[1]} if block.nil?
|
|
69
|
-
super(&block)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
class Array
|
|
74
|
-
def total
|
|
75
|
-
self.inject {|sum,num| sum+num}
|
|
76
|
-
end
|
|
77
|
-
def to_hash
|
|
78
|
-
out_hash = Hash.new
|
|
79
|
-
for pair in self
|
|
80
|
-
raise "Malformed array" unless pair.is_a?(Array) && (pair.length == 2)
|
|
81
|
-
out_hash[pair[0]] = pair[1]
|
|
82
|
-
end
|
|
83
|
-
return out_hash
|
|
84
|
-
end
|
|
85
|
-
alias to_h to_hash
|
|
86
|
-
alias to_hsh to_hash
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
class Numeric
|
|
90
|
-
#Taken from a code snippet by tthorley at http://codesnippets.joyent.com/posts/show/1812
|
|
91
|
-
def self.format(number, value_separator = ",", trailing_zeroes = 2, after = 3, decimal_separator = ".")
|
|
92
|
-
pre,post = number.to_s.split(".")
|
|
93
|
-
pre.gsub(/(\d)(?=(\d{#{after}})+$)/, '\0' + value_separator)+(post ? "#{decimal_separator}#{post == "0" ? "0"*trailing_zeroes : post}" : "")
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
class Struct
|
|
98
|
-
def to_hash
|
|
99
|
-
hash = Hash.new
|
|
100
|
-
for key in self.members
|
|
101
|
-
hash[key] = self[key]
|
|
102
|
-
end
|
|
103
|
-
return hash
|
|
104
|
-
end
|
|
105
|
-
alias to_h to_hash
|
|
106
|
-
alias to_hsh to_hash
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
module Kernel
|
|
110
|
-
def numform(*args)
|
|
111
|
-
Numeric.format(*args)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'lib/libaaron'
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 1
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 1.0.
|
|
8
|
+
- 2
|
|
9
|
+
version: 1.0.2
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Aaron Lynch
|
|
@@ -28,6 +28,7 @@ extra_rdoc_files: []
|
|
|
28
28
|
|
|
29
29
|
files:
|
|
30
30
|
- libaaron.rb
|
|
31
|
+
- lib/libaaron.rb
|
|
31
32
|
- LICENSE
|
|
32
33
|
- VERSION
|
|
33
34
|
has_rdoc: true
|