helpy 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/helpy.gemspec +2 -2
- data/lib/boolean_extension.rb +3 -3
- data/lib/phone_extension.rb +9 -6
- data/spec/money_spec.rb +1 -1
- data/spec/phone_spec.rb +17 -9
- metadata +4 -4
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
17
|
gem.name = "helpy"
|
18
|
-
gem.version = "0.1.
|
18
|
+
gem.version = "0.1.3"
|
19
19
|
gem.homepage = "http://github.com/corsonx/helpy"
|
20
20
|
gem.license = "MIT"
|
21
21
|
gem.summary = "Extensions to strings and numbers to enable phone formatting, money formatting, and true/false testing"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/helpy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "helpy"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brad Corson"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-09-25"
|
13
13
|
s.description = "Check out then readme!"
|
14
14
|
s.email = "nucleardragoninc@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/boolean_extension.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Boolinators
|
2
2
|
def truey?
|
3
3
|
(self == true || ## TrueClass
|
4
|
-
!(self.to_s.strip =~ /^true$|^yes$|^t$|^y$|^1$/i).nil? || ## Strings
|
4
|
+
!(self.to_s.strip =~ /^true$|^yes$|^t$|^y$|^on$|^1$/i).nil? || ## Strings
|
5
5
|
(self == 1 rescue false) ## Integers
|
6
6
|
) ? true : false
|
7
7
|
end
|
@@ -9,9 +9,9 @@ module Boolinators
|
|
9
9
|
def falsey?
|
10
10
|
(self == false || ## FalseClass
|
11
11
|
(self.to_s.empty? rescue false) || ## Empty Strings
|
12
|
-
!(self.to_s.strip =~ /^false$|^no$|^f$|^n$|^0$/i).nil? || ## Strings
|
12
|
+
!(self.to_s.strip =~ /^false$|^no$|^f$|^n$|^off$|^0$/i).nil? || ## Strings
|
13
13
|
(self == 0 rescue false) || ## Integers
|
14
14
|
(self.to_f > 1 rescue false )
|
15
15
|
) ? true : false
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
data/lib/phone_extension.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module PhoneFuncs
|
2
2
|
def phone(options={})
|
3
|
-
options = {:area_sep => '-', :num_sep => '-', :exceptions =>
|
3
|
+
options = {:area_sep => '-', :num_sep => '-', :exceptions => false}.merge(options)
|
4
4
|
ph = self.to_s.gsub(/[^0-9]/, '')
|
5
5
|
area = ''
|
6
6
|
unless ph.length > 0; return ph; end
|
7
|
-
if ph.length ==
|
7
|
+
if ph.length == 11
|
8
|
+
area = options[:area_sep] == '(' ? ph[0..0]+'('+ph[1..3]+')' : ph[0..0] + options[:num_sep] + ph[1..3]+options[:area_sep]
|
9
|
+
ph = [ph[4..6],ph[7..10]].join(options[:num_sep])
|
10
|
+
elsif ph.length == 10
|
8
11
|
area = options[:area_sep] == '(' ? '('+ph[0..2]+')' : ph[0..2]+options[:area_sep]
|
9
12
|
ph = [ph[3..5],ph[6..9]].join(options[:num_sep])
|
10
13
|
elsif ph.length == 7
|
@@ -12,11 +15,11 @@ module PhoneFuncs
|
|
12
15
|
else
|
13
16
|
if options[:exceptions]
|
14
17
|
raise ArgumentError, 'Invalid number of digits for a phone number', caller
|
15
|
-
else
|
16
|
-
area = ''
|
17
|
-
ph = ''
|
18
|
+
#else
|
19
|
+
#area = ''
|
20
|
+
#ph = ''
|
18
21
|
end
|
19
22
|
end
|
20
23
|
area+ph
|
21
24
|
end
|
22
|
-
end
|
25
|
+
end
|
data/spec/money_spec.rb
CHANGED
@@ -119,7 +119,7 @@ describe Bignum do
|
|
119
119
|
(2**(0.size * 8 -2)).monetize({:no_decimal => true}).include?('.00').should eq(false)
|
120
120
|
|
121
121
|
res = (2**(0.size * 8 -2)).monetize({:currency_before => false})
|
122
|
-
res[res.length-1].should eq('$')
|
122
|
+
res[res.length-1,1].should eq('$')
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
data/spec/phone_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe String do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should raise an exception for too-short input" do
|
23
|
-
expect { '551234'.phone }.should raise_exception
|
23
|
+
expect { '551234'.phone({:exceptions => true}) }.should raise_exception
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should allow options" do
|
@@ -28,7 +28,7 @@ describe String do
|
|
28
28
|
'8005551234'.phone({:area_sep => '('}).should eq('(800)555-1234')
|
29
29
|
'8005551234'.phone({:num_sep => '.'}).should eq('800-555.1234')
|
30
30
|
expect { '551234'.phone({:exceptions => false}) }.should_not raise_exception
|
31
|
-
'551234'.phone({:exceptions => false}).should eq('')
|
31
|
+
'551234'.phone({:exceptions => false}).should eq('551234')
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
@@ -45,13 +45,21 @@ describe Fixnum do
|
|
45
45
|
it "should default correctly" do
|
46
46
|
5551234.phone.should eq('555-1234')
|
47
47
|
end
|
48
|
+
|
49
|
+
it "should default correctly for full numbers" do
|
50
|
+
18005551234.phone.should eq('1-800-555-1234')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should use area seperator correctly" do
|
54
|
+
18005551234.phone({:area_sep => '('}).should eq('1(800)555-1234')
|
55
|
+
end
|
48
56
|
|
49
|
-
it "should raise an exception, because a full 10 digit number is
|
50
|
-
expect { 8005551234.phone }.
|
57
|
+
it "should not raise an exception, because a full 10 digit number is valid" do
|
58
|
+
expect { 8005551234.phone({:exceptions => true}) }.should_not raise_exception
|
51
59
|
end
|
52
60
|
|
53
61
|
it "should raise an exception for a too-short number" do
|
54
|
-
expect { 551234.phone }.should raise_exception
|
62
|
+
expect { 551234.phone({:exceptions => true}) }.should raise_exception
|
55
63
|
end
|
56
64
|
|
57
65
|
end
|
@@ -68,16 +76,16 @@ describe Float do
|
|
68
76
|
555123.4.phone.should eq('555-1234')
|
69
77
|
end
|
70
78
|
|
71
|
-
it "should raise an exception,
|
72
|
-
expect { 8005551234.
|
79
|
+
it "should raise an exception, 12 digit number is invalid" do
|
80
|
+
expect { 8005551234.93.phone({:exceptions => true}) }.should raise_exception
|
73
81
|
end
|
74
82
|
|
75
83
|
it "should raise an exception for a too-short number" do
|
76
|
-
expect { 5512.2.phone }.should raise_exception
|
84
|
+
expect { 5512.2.phone({:exceptions => true}) }.should raise_exception
|
77
85
|
end
|
78
86
|
|
79
87
|
it "should raise an exception for a too-long number" do
|
80
|
-
expect { 5551234.2.phone }.should raise_exception
|
88
|
+
expect { 5551234.2.phone({:exceptions => true}) }.should raise_exception
|
81
89
|
end
|
82
90
|
|
83
91
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helpy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brad Corson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-09-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|