koalemos 0.0.1 → 0.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/Rakefile +2 -2
- data/VERSION +1 -1
- data/koalemos.gemspec +4 -4
- data/lib/koalemos.rb +1 -1
- data/lib/koalemos/commaify.rb +2 -2
- data/lib/koalemos/round.rb +21 -15
- data/spec/koalemos_spec.rb +122 -2
- metadata +4 -4
data/Rakefile
CHANGED
@@ -5,8 +5,8 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "koalemos"
|
8
|
-
gem.summary = %Q{
|
9
|
-
gem.description = %Q{
|
8
|
+
gem.summary = %Q{A bunch of small extensions to built in classes/modules}
|
9
|
+
gem.description = %Q{A bunch of small extensions to built in classes/modules}
|
10
10
|
gem.email = "me@talatlas.com"
|
11
11
|
gem.homepage = "http://github.com/Talby/koalemos"
|
12
12
|
gem.authors = ["Tal Atlas"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/koalemos.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{koalemos}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tal Atlas"]
|
12
|
-
s.date = %q{2009-12-
|
13
|
-
s.description = %q{
|
12
|
+
s.date = %q{2009-12-27}
|
13
|
+
s.description = %q{A bunch of small extensions to built in classes/modules}
|
14
14
|
s.email = %q{me@talatlas.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -46,7 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.rdoc_options = ["--charset=UTF-8"]
|
47
47
|
s.require_paths = ["lib"]
|
48
48
|
s.rubygems_version = %q{1.3.5}
|
49
|
-
s.summary = %q{
|
49
|
+
s.summary = %q{A bunch of small extensions to built in classes/modules}
|
50
50
|
s.test_files = [
|
51
51
|
"spec/koalemos_spec.rb",
|
52
52
|
"spec/spec_helper.rb"
|
data/lib/koalemos.rb
CHANGED
data/lib/koalemos/commaify.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Koalemos
|
2
2
|
class ::Numeric
|
3
3
|
unless method_defined?(:commafy)
|
4
|
-
def
|
4
|
+
def commaify
|
5
5
|
to_s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse
|
6
6
|
end
|
7
7
|
end
|
@@ -9,7 +9,7 @@ module Koalemos
|
|
9
9
|
|
10
10
|
class ::Float
|
11
11
|
unless method_defined?(:commafy)
|
12
|
-
def
|
12
|
+
def commaofy
|
13
13
|
to_s.gsub(/\d+\./) do |s|
|
14
14
|
s.reverse.scan(/(?:\d*\.)?\d{1,3}-?/).join(',').reverse
|
15
15
|
end
|
data/lib/koalemos/round.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
module Koalemos
|
2
2
|
# A bit more versatile rounding for Ruby
|
3
|
-
module
|
4
|
-
|
5
|
-
if klass.instance_method(:round)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
else
|
14
|
-
|
15
|
-
end
|
16
|
-
|
3
|
+
module RoundTo
|
4
|
+
# def self.included(klass)
|
5
|
+
# if klass.instance_method(:round)
|
6
|
+
# klass.class_eval do
|
7
|
+
# begin
|
8
|
+
# remove_method :round
|
9
|
+
# rescue NameError
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# super
|
13
|
+
# else
|
14
|
+
# raise NoMethodError, 'no round method found'
|
15
|
+
# end
|
16
|
+
# end
|
17
17
|
|
18
|
-
def
|
18
|
+
def round_to(places = 0)
|
19
19
|
unless Integer === places
|
20
20
|
raise TypeError, "argument places has to be an Integer"
|
21
21
|
end
|
@@ -35,4 +35,10 @@ module Koalemos
|
|
35
35
|
t.nan? ? self : t
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
class ::Float
|
40
|
+
unless method_defined?(:round_to)
|
41
|
+
include RoundTo
|
42
|
+
end
|
43
|
+
end
|
38
44
|
end
|
data/spec/koalemos_spec.rb
CHANGED
@@ -1,7 +1,127 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Koalemos" do
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
describe "beginning_of_day" do
|
6
|
+
it "should work" do
|
7
|
+
Time.now.should respond_to(:beginning_of_day)
|
8
|
+
Time.should respond_to(:beginning_of_day)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
describe "blank?" do
|
14
|
+
it "should work" do
|
15
|
+
nil.blank?.should be_true
|
16
|
+
[].blank?.should be_true
|
17
|
+
[1].blank?.should be_false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "commaify" do
|
22
|
+
it "should work for fixnum" do
|
23
|
+
1234567890.commaify.should eql("1,234,567,890")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work for float" do
|
27
|
+
1234567890.1234567890.commaify.should eql("1,234,567,890.12346")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "friendly time" do
|
32
|
+
it "should work" do
|
33
|
+
(Time.now - 1.day).friendly.should eql("1 day ago")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "full" do
|
38
|
+
it "should work" do
|
39
|
+
nil.full?(:test){|p|p.inspect}.should be_nil
|
40
|
+
"12".full?.should == "12"
|
41
|
+
"12".full?(:to_i).should == 12
|
42
|
+
12.full?{|n| n/2}.should == 6
|
43
|
+
"13".full?(:to_f){|n| n/2}.should == 6.5
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "hash union" do
|
48
|
+
it "should_work" do
|
49
|
+
h1 = {:foo => 'foo',:bar => 'bar'}
|
50
|
+
h1 |= {:foo => 'none',:baz => 'baz'}
|
51
|
+
h1.should == {:foo => 'foo',:bar => 'bar',:baz => 'baz'}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "num_to_time" do
|
56
|
+
describe "number to seconds" do
|
57
|
+
it "should convert times from fixnum" do
|
58
|
+
1.minute.should eql(60)
|
59
|
+
1.hour.should eql(60.minutes)
|
60
|
+
1.day.should eql(24.hours)
|
61
|
+
1.week.should eql(7.days)
|
62
|
+
1.month.should eql(30.days)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should convert times from floats" do
|
66
|
+
1.5.minutes.should eql(90.0)
|
67
|
+
365.0.days.should eql(1.0.year)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "getting time from number" do
|
72
|
+
it "should get 1 day ago"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "odd" do
|
77
|
+
it "should work" do
|
78
|
+
1.odd?.should be_true
|
79
|
+
2.odd?.should be_false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "rand" do
|
84
|
+
it "pick should work" do
|
85
|
+
[1].pick.should == 1
|
86
|
+
a = [1,2,3]
|
87
|
+
n = a.pick!
|
88
|
+
n.should be_close(2, 1.1)
|
89
|
+
newa = [1,2,3]
|
90
|
+
newa.delete(n)
|
91
|
+
a.should == (newa)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "shuffle should work" do
|
95
|
+
a = [*1..1000].shuffle
|
96
|
+
a[0,2].should_not == [*1..2]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "round_to" do
|
101
|
+
it "should_work" do
|
102
|
+
123.123.round_to.should == 123
|
103
|
+
123.456.round_to.should == 123
|
104
|
+
123.556.round_to.should == 124
|
105
|
+
123.123.round_to(1).should == 123.1
|
106
|
+
123.156.round_to(1).should == 123.2
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "symbol_to_proc" do
|
111
|
+
it "should_work" do
|
112
|
+
pending "need to find use"
|
113
|
+
%w{1 2 3 4}.each(:to_i).should == [1,2,3,4]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "uniq_by" do
|
118
|
+
it "should work" do
|
119
|
+
[ {:key => 'foo'},
|
120
|
+
{:key => 'foo'},
|
121
|
+
{:key => 'bar'},
|
122
|
+
{:key => 'baz'},
|
123
|
+
{:key => 'bbaz'}].uniq_by{|a| a[:key]}.
|
124
|
+
should eql([{:key=>"bbaz"}, {:key=>"baz"}, {:key=>"foo"}, {:key=>"bar"}])
|
125
|
+
end
|
6
126
|
end
|
7
127
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koalemos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tal Atlas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-27 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
-
description:
|
35
|
+
description: A bunch of small extensions to built in classes/modules
|
36
36
|
email: me@talatlas.com
|
37
37
|
executables: []
|
38
38
|
|
@@ -93,7 +93,7 @@ rubyforge_project:
|
|
93
93
|
rubygems_version: 1.3.5
|
94
94
|
signing_key:
|
95
95
|
specification_version: 3
|
96
|
-
summary:
|
96
|
+
summary: A bunch of small extensions to built in classes/modules
|
97
97
|
test_files:
|
98
98
|
- spec/koalemos_spec.rb
|
99
99
|
- spec/spec_helper.rb
|