simple_model 0.1.6 → 0.1.7

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/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_model (0.1.6)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rspec (2.4.0)
11
+ rspec-core (~> 2.4.0)
12
+ rspec-expectations (~> 2.4.0)
13
+ rspec-mocks (~> 2.4.0)
14
+ rspec-core (2.4.0)
15
+ rspec-expectations (2.4.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.4.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec (= 2.4.0)
24
+ simple_model!
@@ -1,6 +1,6 @@
1
1
  module ExtendCore
2
- require 'time'
3
- require 'date'
2
+ require 'time'
3
+ require 'date'
4
4
 
5
5
  Float.class_eval do
6
6
  def round_to(precision)
@@ -13,6 +13,22 @@ require 'date'
13
13
  def to_currency
14
14
  round_to(0.01)
15
15
  end
16
+
17
+ #Returns string with representation of currency
18
+ def to_currency_s(symbol="$")
19
+ num = "#{self.to_currency}"
20
+ num << "." unless num.include?(".")
21
+ while num.index('.') != (num.length-3)
22
+ num << '0'
23
+ end
24
+ comma = 6
25
+ while num.length > (comma)
26
+ num.insert((num.length - comma), ",")
27
+ comma += 4
28
+ end
29
+ num.insert(0,symbol)
30
+ num
31
+ end
16
32
  end
17
33
 
18
34
  Object.class_eval do
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/simple_model.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.summary = %q{Simpifies building tableless models or models backed by webservices}
14
14
  s.description = %q{Simpifies building tableless models or models backed by webservices. Create data type specific attributes with default if values. Also, provides a simple error and validation api for non-rails 3 apps.}
15
15
 
16
- s.add_development_dependency 'rspec', ' 1.3.1'
16
+ s.add_development_dependency 'rspec', ' 2.4.0'
17
17
  s.rubyforge_project = "simple_model"
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
@@ -4,6 +4,7 @@ describe ExtendCore, 'Float.rb' do
4
4
  before(:all) do
5
5
  include ExtendCore
6
6
  end
7
+
7
8
  describe ExtendCore, 'round_to' do
8
9
  it "should return float rounded to specified precision" do
9
10
  0.3333.round_to(0.01).should eql(0.33)
@@ -11,6 +12,27 @@ describe ExtendCore, 'Float.rb' do
11
12
  0.33335.round_to(0.0001).should eql(0.3334)
12
13
  end
13
14
  end
15
+
16
+ describe ExtendCore, 'to_currency_s' do
17
+ it "should return a string" do
18
+ 0.333.to_currency_s.class.should eql(String)
19
+ end
20
+ it "should prefix string with currency symbol" do
21
+ 5.12.to_currency_s.include?("$").should be_true
22
+ end
23
+ it "should padd with zeros for cents" do
24
+ 5.0.to_currency_s.should eql("$5.00")
25
+ end
26
+ it "should round string to nearest tenth" do
27
+ 0.333.to_currency_s.should eql("$0.33")
28
+ end
29
+ it "should add commas to long numbers" do
30
+ 500000000000.0.to_currency_s.should eql("$500,000,000,000.00")
31
+ 50000000000.0.to_currency_s.should eql("$50,000,000,000.00")
32
+ 5000000000.0.to_currency_s.should eql("$5,000,000,000.00")
33
+ end
34
+ end
35
+
14
36
  end
15
37
 
16
38
 
@@ -26,6 +48,7 @@ describe ExtendCore, 'String.rb' do
26
48
 
27
49
  end
28
50
  end
51
+
29
52
  describe ExtendCore, 'to_b' do
30
53
  it "should return a Boolean" do
31
54
  "1".to_b.class.should eql(TrueClass)
@@ -36,9 +59,9 @@ describe ExtendCore, 'String.rb' do
36
59
  ['1','t','true'].each do |s|
37
60
  s.to_b.should be_true
38
61
  end
39
- end
40
-
62
+ end
41
63
  end
64
+
42
65
  describe ExtendCore, 'to_date' do
43
66
  it "return a Date object" do
44
67
  "12/31/2010".to_date.class.should eql(Date)
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'simple_model'
4
- require 'spec'
4
+ require 'rspec'
5
5
 
6
6
 
7
7
 
@@ -10,7 +10,7 @@ require 'spec'
10
10
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
11
 
12
12
 
13
- Spec::Runner.configure do |config|
13
+ RSpec.configure do |config|
14
14
 
15
15
 
16
16
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua T Mckinney
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-03 00:00:00 -06:00
17
+ date: 2011-02-07 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -26,10 +26,10 @@ dependencies:
26
26
  - - "="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
- - 1
30
- - 3
31
- - 1
32
- version: 1.3.1
29
+ - 2
30
+ - 4
31
+ - 0
32
+ version: 2.4.0
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  description: Simpifies building tableless models or models backed by webservices. Create data type specific attributes with default if values. Also, provides a simple error and validation api for non-rails 3 apps.
@@ -45,6 +45,7 @@ files:
45
45
  - .autotest
46
46
  - .gitignore
47
47
  - Gemfile
48
+ - Gemfile.lock
48
49
  - LICENSE.txt
49
50
  - README.md
50
51
  - Rakefile