helpy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "rcov", ">= 0"
14
+ gem "rspec"
15
+ end
@@ -0,0 +1,51 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.13)
5
+ i18n (= 0.6.1)
6
+ multi_json (~> 1.0)
7
+ bourne (1.4.0)
8
+ mocha (~> 0.13.2)
9
+ diff-lcs (1.2.2)
10
+ git (1.2.5)
11
+ i18n (0.6.1)
12
+ jeweler (1.8.4)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.7.7)
18
+ metaclass (0.0.1)
19
+ mocha (0.13.3)
20
+ metaclass (~> 0.0.1)
21
+ multi_json (1.7.2)
22
+ rake (10.0.4)
23
+ rcov (1.0.0)
24
+ rdoc (3.12.2)
25
+ json (~> 1.4)
26
+ rspec (2.13.0)
27
+ rspec-core (~> 2.13.0)
28
+ rspec-expectations (~> 2.13.0)
29
+ rspec-mocks (~> 2.13.0)
30
+ rspec-core (2.13.1)
31
+ rspec-expectations (2.13.0)
32
+ diff-lcs (>= 1.1.3, < 2.0)
33
+ rspec-mocks (2.13.1)
34
+ shoulda (3.4.0)
35
+ shoulda-context (~> 1.0, >= 1.0.1)
36
+ shoulda-matchers (~> 1.0, >= 1.4.1)
37
+ shoulda-context (1.1.0)
38
+ shoulda-matchers (1.5.6)
39
+ activesupport (>= 3.0.0)
40
+ bourne (~> 1.3)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.0.0)
47
+ jeweler (~> 1.8.4)
48
+ rcov
49
+ rdoc (~> 3.12)
50
+ rspec
51
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Brad Corson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ = helpy
2
+
3
+ Helpy, well, helps you. It extends several of ruby's classes to add some
4
+ functionality.
5
+
6
+ 1) You can call .monetize on a string or number, and it returns
7
+ a formatted string that looks like, well, a dollar value. Default format is
8
+ U.S. formatting, but you can pass a hash of options in to change the format.
9
+ The defaults look like this: {:currency_symbol => "$", :delimiter => ",",
10
+ :decimal => ".", :currency_before => true, :no_decimal => false}. You only
11
+ need to supply the values you are changing.
12
+
13
+ 2) Call .phone on any number or string. The number or string must contain
14
+ exactly 7 or 10 digits (strings can contain any number of other characters,
15
+ they get stripped out). Again, you can change the formatting. Here are the
16
+ defaults: {:area_sep => '-', :num_sep => '-', :exceptions => true}. If you
17
+ pass a '(' as the area separator, helpy will wrap the area in open-and-closing
18
+ parens.
19
+
20
+ 3) True and false testing! This is great for data returned from html forms,
21
+ legacy systems, or anything that has an unknown or variable 'true/false'
22
+ format. Call .truey? on any Boolean, FixNum, Float, Bignum or String. If the value is
23
+ a true, 1, or is a string consisting of only 'true', 'yes', 't', 'y', or '1'
24
+ (case-insensitive), helpy returns true. Call .falsy? to return whether it
25
+ looks false. falsy? also returns false for empty strings.
26
+
27
+ == Contributing to helpy
28
+
29
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
30
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
31
+ * Fork the project.
32
+ * Start a feature/bugfix branch.
33
+ * Commit and push until you are happy with your contribution.
34
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
35
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
36
+
37
+ == Copyright
38
+
39
+ Copyright (c) 2013 Brad Corson. See LICENSE.txt for
40
+ further details.
41
+
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "helpy"
18
+ gem.version = "0.1.0"
19
+ gem.homepage = "http://github.com/corsonx/helpy"
20
+ gem.license = "MIT"
21
+ gem.summary = "Extensions to strings and numbers to enable phone formatting, money formatting, and true/false testing"
22
+ gem.description = "Check out then readme!"
23
+ gem.email = "nucleardragoninc@gmail.com"
24
+ gem.authors = ["Brad Corson"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rdoc/task'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "helpy #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "helpy"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brad Corson"]
12
+ s.date = "2013-04-08"
13
+ s.description = "Check out then readme!"
14
+ s.email = "nucleardragoninc@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "helpy.gemspec",
28
+ "lib/boolean_extension.rb",
29
+ "lib/helpy.rb",
30
+ "lib/money_extension.rb",
31
+ "lib/phone_extension.rb",
32
+ "spec/boolean_spec.rb",
33
+ "spec/money_spec.rb",
34
+ "spec/phone_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "test/helper.rb",
37
+ "test/test_helpy.rb"
38
+ ]
39
+ s.homepage = "http://github.com/corsonx/helpy"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.15"
43
+ s.summary = "Extensions to strings and numbers to enable phone formatting, money formatting, and true/false testing"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
53
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ s.add_development_dependency(%q<rspec>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<shoulda>, [">= 0"])
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ s.add_dependency(%q<rspec>, [">= 0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,17 @@
1
+ module Boolinators
2
+ def truey?
3
+ (self == true || ## TrueClass
4
+ !(self.to_s.strip =~ /^true$|^yes$|^t$|^y$|^1$/i).nil? || ## Strings
5
+ (self == 1 rescue false) ## Integers
6
+ ) ? true : false
7
+ end
8
+
9
+ def falsey?
10
+ (self == false || ## FalseClass
11
+ (self.to_s.empty? rescue false) || ## Empty Strings
12
+ !(self.to_s.strip =~ /^false$|^no$|^f$|^n$|^0$/i).nil? || ## Strings
13
+ (self == 0 rescue false) || ## Integers
14
+ (self.to_f > 1 rescue false )
15
+ ) ? true : false
16
+ end
17
+ end
@@ -0,0 +1,46 @@
1
+ =begin rdoc
2
+
3
+ = Helpy - Ruby Class Extensions
4
+
5
+ Author:: Bradley Corson, Jr., brad@unclehenrys.com
6
+
7
+ Extend FixNum, Float, Bignum and String with phone, money and boolean functionality.
8
+
9
+ =end
10
+
11
+ $LOAD_PATH.unshift File.dirname(__FILE__)
12
+ require 'lib/boolean_extension'
13
+ require 'lib/phone_extension'
14
+ require 'lib/money_extension'
15
+
16
+ class Fixnum
17
+ include Boolinators
18
+ include MoneyFuncs
19
+ include PhoneFuncs
20
+ end
21
+
22
+ class Float
23
+ include Boolinators
24
+ include MoneyFuncs
25
+ include PhoneFuncs ## The entire value is converted to a number. Ex 555123.4 = '555-1234'
26
+ end
27
+
28
+ class Bignum
29
+ include Boolinators
30
+ include MoneyFuncs ## Bignum is converted to a Fixnum before monetizing
31
+ include PhoneFuncs
32
+ end
33
+
34
+ class String
35
+ include Boolinators
36
+ include MoneyFuncs
37
+ include PhoneFuncs
38
+ end
39
+
40
+ class TrueClass
41
+ include Boolinators
42
+ end
43
+
44
+ class FalseClass
45
+ include Boolinators
46
+ end
@@ -0,0 +1,21 @@
1
+ module MoneyFuncs
2
+ def monetize(options={})
3
+ # default format: $12,345,678.90
4
+ options = {:currency_symbol => "$", :delimiter => ",", :decimal => ".",
5
+ :currency_before => true, :no_decimal => false}.merge(options)
6
+ if self.class == Bignum
7
+ parts = self.to_s.gsub(/[^0-9^.]/, '').split('.')
8
+ int = parts[0] or '0'
9
+ frac = parts[1].nil? ? '00' : parts[1]
10
+ else
11
+ int, frac = ("%.2f" % self.to_s.gsub(/[^0-9^.]/, '')).split('.')
12
+ end
13
+ int.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
14
+ frac_part = options[:no_decimal] ? "" : options[:decimal] + frac
15
+ if options[:currency_before]
16
+ options[:currency_symbol] + int + frac_part
17
+ else
18
+ int + frac_part + options[:currency_symbol]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module PhoneFuncs
2
+ def phone(options={})
3
+ options = {:area_sep => '-', :num_sep => '-', :exceptions => true}.merge(options)
4
+ ph = self.to_s.gsub(/[^0-9]/, '')
5
+ area = ''
6
+ unless ph.length > 0; return ph; end
7
+ if ph.length == 10
8
+ area = options[:area_sep] == '(' ? '('+ph[0..2]+')' : ph[0..2]+options[:area_sep]
9
+ ph = [ph[3..5],ph[6..9]].join(options[:num_sep])
10
+ elsif ph.length == 7
11
+ ph = [ph[0..2],ph[3..6]].join(options[:num_sep])
12
+ else
13
+ if options[:exceptions]
14
+ raise ArgumentError, 'Invalid number of digits for a phone number', caller
15
+ else
16
+ area = ''
17
+ ph = ''
18
+ end
19
+ end
20
+ area+ph
21
+ end
22
+ end
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/boolean_extension'
3
+
4
+ describe String do
5
+
6
+ before(:all) do
7
+ class String
8
+ include Boolinators
9
+ end
10
+ end
11
+
12
+ it "should consider true for a string of 't' or 'true', regardless of capitalization" do
13
+ ['t', 'T', 'true', 'True', 'TrUe'].each do |str|
14
+ str.truey?.should eq(true)
15
+ str.falsey?.should eq(false)
16
+ end
17
+ end
18
+
19
+ it "should consider true for a string of 'y' or 'yes', regardless of capitalization" do
20
+ ['y', 'Y', 'yes', 'Yes', 'YeS'].each do |str|
21
+ str.truey?.should eq(true)
22
+ str.falsey?.should eq(false)
23
+ end
24
+ end
25
+
26
+ it "should consider true for a string of '1'" do
27
+ '1'.truey?.should eq(true)
28
+ '1'.falsey?.should eq(false)
29
+ end
30
+
31
+ it "should consider false for a string of 'f' or 'false', regardless of capitalization" do
32
+ ['f', 'F', 'false', 'False', 'FALSE'].each do |str|
33
+ str.falsey?.should eq(true)
34
+ str.truey?.should eq(false)
35
+ end
36
+ end
37
+
38
+ it "should consider false for a string of 'n' or 'no', regardless of capitalization" do
39
+ ['n', 'N', 'no', 'No', 'NO'].each do |str|
40
+ str.falsey?.should eq(true)
41
+ str.truey?.should eq(false)
42
+ end
43
+ end
44
+
45
+ it "should consider false for an empty string" do
46
+ ''.falsey?.should eq(true)
47
+ ''.truey?.should eq(false)
48
+ end
49
+
50
+ it "should consider false for a string of '0'" do
51
+ '0'.falsey?.should eq(true)
52
+ '0'.truey?.should eq(false)
53
+ end
54
+
55
+ end
56
+
57
+ #######################
58
+ describe TrueClass do
59
+
60
+ before(:all) do
61
+ class TrueClass
62
+ include Boolinators
63
+ end
64
+ end
65
+
66
+ it "should consider true as true for TrueClass" do
67
+ true.truey?.should eq(true)
68
+ true.falsey?.should eq(false)
69
+ end
70
+
71
+ end
72
+
73
+ #######################
74
+ describe FalseClass do
75
+
76
+ before(:all) do
77
+ class FalseClass
78
+ include Boolinators
79
+ end
80
+ end
81
+
82
+ it "should consider false as false for FalseClass" do
83
+ false.truey?.should eq(false)
84
+ false.falsey?.should eq(true)
85
+ end
86
+
87
+ end
88
+
89
+ #######################
90
+ describe Fixnum do
91
+
92
+ before(:all) do
93
+ class Fixnum
94
+ include Boolinators
95
+ end
96
+ end
97
+
98
+ it "should consider true for integers == 1" do
99
+ 1.truey?.should eq(true)
100
+ 1.falsey?.should eq(false)
101
+ end
102
+
103
+ it "should consider false for integers other than 0 or 1" do
104
+ [2, 45, 100].each do |i|
105
+ i.truey?.should eq(false)
106
+ i.falsey?.should eq(true)
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ #######################
113
+ describe Float do
114
+
115
+ before(:all) do
116
+ class Float
117
+ include Boolinators
118
+ end
119
+ end
120
+
121
+ it "should consider true for floats == 1.0" do
122
+ 1.0.truey?.should eq(true)
123
+ 1.0.falsey?.should eq(false)
124
+ end
125
+
126
+ it "should consider false for floats == 0.0" do
127
+ 0.0.truey?.should eq(false)
128
+ 0.0.falsey?.should eq(true)
129
+ end
130
+
131
+ it "should consider false for floats > 1.0" do
132
+ [1.1, 15.2, 123.0].each do |i|
133
+ i.truey?.should eq(false)
134
+ i.falsey?.should eq(true)
135
+ end
136
+ end
137
+
138
+ end
139
+
140
+ #######################
141
+ describe Bignum do
142
+
143
+ before(:all) do
144
+ class Bignum
145
+ include Boolinators
146
+ end
147
+ end
148
+
149
+ it "should consider false for all Bignum's" do
150
+ (2**(0.size * 8 -2)).truey?.should eq(false) ## minimum Bignum
151
+ (2**(0.size * 8 -2)).falsey?.should eq(true)
152
+
153
+ ((2**(0.size * 8 -2))*2).truey?.should eq(false) ## double minimum Bignum
154
+ ((2**(0.size * 8 -2))*2).falsey?.should eq(true)
155
+ end
156
+
157
+ end
158
+
159
+
160
+
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/money_extension'
3
+
4
+ describe String do
5
+
6
+ before(:all) do
7
+ class String
8
+ include MoneyFuncs
9
+ end
10
+ end
11
+
12
+ it "should default to US currency" do
13
+ '123456'.monetize.should eq('$123,456.00')
14
+ '123'.monetize.should eq('$123.00')
15
+ end
16
+
17
+ it "should have no decimal when specified" do
18
+ '123456'.monetize({:no_decimal => true}).should eq('$123,456')
19
+ '123456.00'.monetize({:no_decimal => true}).should eq('$123,456')
20
+ '123456.50'.monetize({:no_decimal => true}).should eq('$123,456')
21
+ end
22
+
23
+ it "should allow you to specify where the money symbol is" do
24
+ '123456'.monetize({:currency_before => false}).should eq('123,456.00$')
25
+ '123456.00'.monetize({:currency_before => false, :no_decimal => true}).should eq('123,456$')
26
+ end
27
+
28
+ it "should allow you to specify what the money symbol is" do
29
+ '123456'.monetize({:currency_symbol => '^'}).should eq('^123,456.00')
30
+ '123456.00'.monetize({:currency_symbol => '^',
31
+ :currency_before => false,
32
+ :no_decimal => true}).should eq('123,456^')
33
+ end
34
+
35
+ it "should allow you to specify what the decimal symbol is" do
36
+ '123456'.monetize({:decimal => ';'}).should eq('$123,456;00')
37
+ '123456.00'.monetize({:decimal => ';',
38
+ :no_decimal => true}).should eq('$123,456')
39
+ end
40
+
41
+ it "should allow you to specify what the delimiter symbol is" do
42
+ '123456'.monetize({:delimiter => '.'}).should eq('$123.456.00')
43
+ '123456.00'.monetize({:delimiter => '.',
44
+ :no_decimal => true}).should eq('$123.456')
45
+ end
46
+
47
+ end
48
+
49
+ #######################
50
+ describe Fixnum do
51
+
52
+ before(:all) do
53
+ class Fixnum
54
+ include MoneyFuncs
55
+ end
56
+ end
57
+
58
+ it "should default to US currency" do
59
+ 123456.monetize.should eq('$123,456.00')
60
+ 123.monetize.should eq('$123.00')
61
+ end
62
+
63
+ it "should allow all options" do
64
+ 123456.monetize({:currency_symbol => '^',
65
+ :currency_before => false,
66
+ :delimiter => '.',
67
+ :no_decimal => true}).should eq('123.456^')
68
+ end
69
+ end
70
+
71
+ #######################
72
+ describe Float do
73
+ before(:all) do
74
+ class Float
75
+ include MoneyFuncs
76
+ end
77
+ end
78
+
79
+ it "should default to US currency" do
80
+ 123456.0.monetize.should eq('$123,456.00')
81
+ 123.0.monetize.should eq('$123.00')
82
+ 123.50.monetize.should eq('$123.50')
83
+ 123.56.monetize.should eq('$123.56')
84
+ end
85
+
86
+ it "should round to the nearest penny" do
87
+ 123.5678.monetize.should eq('$123.57')
88
+ 123.562.monetize.should eq('$123.56')
89
+ end
90
+
91
+ it "should allow all options" do
92
+ 123456.0.monetize({:currency_symbol => '^',
93
+ :currency_before => false,
94
+ :delimiter => '.',
95
+ :no_decimal => true}).should eq('123.456^')
96
+ end
97
+ end
98
+
99
+ #######################
100
+ describe Bignum do
101
+ before(:all) do
102
+ class Bignum
103
+ include MoneyFuncs
104
+ end
105
+ end
106
+
107
+ it "should equal max Fixnum money display" do
108
+ ## Bignum size differs across systems
109
+ expect { (2**(0.size * 8 -2)).monetize }.should_not raise_exception
110
+
111
+ ## is the monetized length greater than the largest Fixnum conversion
112
+ ((2**(0.size * 8 -2))*20).monetize.length.should be > (2**(0.size * 8 -2) -1).monetize.length
113
+
114
+ end
115
+
116
+ it "should allow options" do
117
+ (2**(0.size * 8 -2)).monetize({:currency_symbol => '^'}).include?('^').should eq(true)
118
+ (2**(0.size * 8 -2)).monetize({:delimiter => '*'}).include?('*').should eq(true)
119
+ (2**(0.size * 8 -2)).monetize({:no_decimal => true}).include?('.00').should eq(false)
120
+
121
+ res = (2**(0.size * 8 -2)).monetize({:currency_before => false})
122
+ res[res.length-1].should eq('$')
123
+ end
124
+ end
125
+
126
+
127
+
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+ require File.dirname(__FILE__) + '/../lib/phone_extension'
3
+
4
+ describe String do
5
+
6
+ before(:all) do
7
+ class String
8
+ include PhoneFuncs
9
+ end
10
+ end
11
+
12
+ it "should default correctly" do
13
+ '8005551234'.phone.should eq('800-555-1234')
14
+ '5551234'.phone.should eq('555-1234')
15
+ end
16
+
17
+ it "should strip non-digits before converting" do
18
+ '800.555.1234'.phone.should eq('800-555-1234')
19
+ '555|1234'.phone.should eq('555-1234')
20
+ end
21
+
22
+ it "should raise an exception for too-short input" do
23
+ expect { '551234'.phone }.should raise_exception
24
+ end
25
+
26
+ it "should allow options" do
27
+ '8005551234'.phone({:area_sep => '.'}).should eq('800.555-1234')
28
+ '8005551234'.phone({:area_sep => '('}).should eq('(800)555-1234')
29
+ '8005551234'.phone({:num_sep => '.'}).should eq('800-555.1234')
30
+ expect { '551234'.phone({:exceptions => false}) }.should_not raise_exception
31
+ '551234'.phone({:exceptions => false}).should eq('')
32
+ end
33
+
34
+ end
35
+
36
+ #######################
37
+ describe Fixnum do
38
+
39
+ before(:all) do
40
+ class Fixnum
41
+ include PhoneFuncs
42
+ end
43
+ end
44
+
45
+ it "should default correctly" do
46
+ 5551234.phone.should eq('555-1234')
47
+ end
48
+
49
+ it "should raise an exception, because a full 10 digit number is a Bignum" do
50
+ expect { 8005551234.phone }.should raise_exception
51
+ end
52
+
53
+ it "should raise an exception for a too-short number" do
54
+ expect { 551234.phone }.should raise_exception
55
+ end
56
+
57
+ end
58
+
59
+ #######################
60
+ describe Float do
61
+ before(:all) do
62
+ class Float
63
+ include PhoneFuncs
64
+ end
65
+ end
66
+
67
+ it "should default correctly" do
68
+ 555123.4.phone.should eq('555-1234')
69
+ end
70
+
71
+ it "should raise an exception, because a full 10 digit number is a Bignum" do
72
+ expect { 8005551234.3.phone }.should raise_exception
73
+ end
74
+
75
+ it "should raise an exception for a too-short number" do
76
+ expect { 5512.2.phone }.should raise_exception
77
+ end
78
+
79
+ it "should raise an exception for a too-long number" do
80
+ expect { 5551234.2.phone }.should raise_exception
81
+ end
82
+
83
+ end
84
+
85
+ #######################
86
+ describe Bignum do
87
+ before(:all) do
88
+ class Bignum
89
+ include PhoneFuncs
90
+ end
91
+ end
92
+
93
+ it "should default correctly with large numbers" do
94
+ 5551234.phone.should eq('555-1234')
95
+ end
96
+
97
+ it "should default correctly" do
98
+ 8005551234.phone.should eq('800-555-1234')
99
+ end
100
+
101
+
102
+ end
103
+
104
+
105
+
File without changes
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'helpy'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestHelpy < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: helpy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Brad Corson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-04-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
31
+ name: shoulda
32
+ prerelease: false
33
+ type: :development
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ hash: 31
41
+ segments:
42
+ - 3
43
+ - 12
44
+ version: "3.12"
45
+ version_requirements: *id002
46
+ name: rdoc
47
+ prerelease: false
48
+ type: :development
49
+ - !ruby/object:Gem::Dependency
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ hash: 23
56
+ segments:
57
+ - 1
58
+ - 0
59
+ - 0
60
+ version: 1.0.0
61
+ version_requirements: *id003
62
+ name: bundler
63
+ prerelease: false
64
+ type: :development
65
+ - !ruby/object:Gem::Dependency
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ hash: 63
72
+ segments:
73
+ - 1
74
+ - 8
75
+ - 4
76
+ version: 1.8.4
77
+ version_requirements: *id004
78
+ name: jeweler
79
+ prerelease: false
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ version_requirements: *id005
92
+ name: rcov
93
+ prerelease: false
94
+ type: :development
95
+ - !ruby/object:Gem::Dependency
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ version_requirements: *id006
106
+ name: rspec
107
+ prerelease: false
108
+ type: :development
109
+ description: Check out then readme!
110
+ email: nucleardragoninc@gmail.com
111
+ executables: []
112
+
113
+ extensions: []
114
+
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ files:
119
+ - .document
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.rdoc
124
+ - Rakefile
125
+ - VERSION
126
+ - helpy.gemspec
127
+ - lib/boolean_extension.rb
128
+ - lib/helpy.rb
129
+ - lib/money_extension.rb
130
+ - lib/phone_extension.rb
131
+ - spec/boolean_spec.rb
132
+ - spec/money_spec.rb
133
+ - spec/phone_spec.rb
134
+ - spec/spec_helper.rb
135
+ - test/helper.rb
136
+ - test/test_helpy.rb
137
+ homepage: http://github.com/corsonx/helpy
138
+ licenses:
139
+ - MIT
140
+ post_install_message:
141
+ rdoc_options: []
142
+
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
162
+ version: "0"
163
+ requirements: []
164
+
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.15
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: Extensions to strings and numbers to enable phone formatting, money formatting, and true/false testing
170
+ test_files: []
171
+