footing 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,5 +4,5 @@ group :development do
4
4
  gem "micro_test"
5
5
  gem "micro_mock"
6
6
  gem "pry"
7
- # gem "pry-stack_explorer"
7
+ gem "pry-stack_explorer"
8
8
  end
@@ -1,6 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ binding_of_caller (0.6.8)
4
5
  coderay (1.0.8)
5
6
  method_source (0.8.1)
6
7
  micro_mock (0.1.1)
@@ -16,6 +17,8 @@ GEM
16
17
  method_source (~> 0.8)
17
18
  slop (~> 3.3.1)
18
19
  spoon (~> 0.0)
20
+ pry-stack_explorer (0.4.7)
21
+ binding_of_caller (~> 0.6.8)
19
22
  slop (3.3.3)
20
23
  spoon (0.0.1)
21
24
 
@@ -27,3 +30,4 @@ DEPENDENCIES
27
30
  micro_mock
28
31
  micro_test
29
32
  pry
33
+ pry-stack_explorer
@@ -51,5 +51,20 @@ module Footing
51
51
  !!(self =~ /\A(true|false)\z/i)
52
52
  end
53
53
 
54
+ # Casts this string to another datatype.
55
+ # Supported datatypes:
56
+ # * Integer
57
+ # * Float
58
+ # * Boolean
59
+ def cast
60
+ return to_f if numeric? && index(".")
61
+ return to_i if numeric?
62
+ if boolean?
63
+ return true if self =~ /\Atrue\z/i
64
+ return false if self =~ /\Afalse\z/i
65
+ end
66
+ self
67
+ end
68
+
54
69
  end
55
70
  end
@@ -1,3 +1,3 @@
1
1
  module Footing
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -2,10 +2,10 @@ require File.join(File.dirname(__FILE__), "test_helper")
2
2
 
3
3
  class StringTest < MicroTest::Test
4
4
  Footing.util! Footing::String
5
+ Footing.patch! String, Footing::String
5
6
 
6
7
  test "patch a string instance" do
7
8
  s = ""
8
- Footing.patch! s, Footing::String
9
9
  assert s.respond_to? :escape
10
10
  assert s.respond_to? :humanize
11
11
  assert s.respond_to? :titleize
@@ -18,6 +18,9 @@ class StringTest < MicroTest::Test
18
18
  assert Footing::String.respond_to? :humanize
19
19
  assert Footing::String.respond_to? :titleize
20
20
  assert Footing::String.respond_to? :titlecase
21
+ assert Footing::String.respond_to? :boolean?
22
+ assert Footing::String.respond_to? :numeric?
23
+ assert Footing::String.respond_to? :cast
21
24
  end
22
25
 
23
26
  test ".random" do
@@ -35,27 +38,20 @@ class StringTest < MicroTest::Test
35
38
  end
36
39
 
37
40
  test ".escape" do
38
- s = "foobar"
39
- Footing.patch! s, Footing::String
40
- assert s.escape("b") == "foo\\bar"
41
+ assert "foobar".escape("b") == "foo\\bar"
41
42
  end
42
43
 
43
44
  test ".titleize" do
44
- s = "foobar test"
45
- Footing.patch! s, Footing::String
46
- assert s.titleize == "Foobar test"
45
+ assert "foobar test".titleize == "Foobar test"
47
46
  end
48
47
 
49
48
  test ".humanize" do
50
- s = "foo_bar"
51
- Footing.patch! s, Footing::String
52
- assert s.humanize == "Foo bar"
49
+ assert "foo_bar".humanize == "Foo bar"
53
50
  end
54
51
 
55
52
  test ".numeric? integers" do
56
53
  (0..100).each do |i|
57
54
  s = i.to_s
58
- Footing.patch! s, Footing::String
59
55
  assert s.numeric?
60
56
  end
61
57
  end
@@ -63,33 +59,25 @@ class StringTest < MicroTest::Test
63
59
  test ".numeric? floats" do
64
60
  (0..100).each do |i|
65
61
  s = i.to_f.to_s
66
- Footing.patch! s, Footing::String
67
62
  assert s.numeric?
68
63
  end
69
- s = "7843.7897389"
70
- Footing.patch! s, Footing::String
71
- assert s.numeric?
72
- s = "7843.789.7389"
73
- Footing.patch! s, Footing::String
74
- assert !s.numeric?
64
+ assert "7843.7897389".numeric?
65
+ assert !"7843.789.7389".numeric?
75
66
  end
76
67
 
77
68
  test ".boolean?" do
78
- s = "true"
79
- Footing.patch! s, Footing::String
80
- assert s.boolean?
81
-
82
- s = "false"
83
- Footing.patch! s, Footing::String
84
- assert s.boolean?
85
-
86
- s = " true"
87
- Footing.patch! s, Footing::String
88
- assert !s.boolean?
69
+ assert "true".boolean?
70
+ assert "false".boolean?
71
+ assert !" true".boolean?
72
+ assert !"false ".boolean?
73
+ end
89
74
 
90
- s = "false "
91
- Footing.patch! s, Footing::String
92
- assert !s.boolean?
75
+ test ".cast" do
76
+ assert "1.23".cast == 1.23
77
+ assert "87843".cast == 87843
78
+ assert "true".cast == true
79
+ assert "false".cast == false
93
80
  end
94
81
 
82
+
95
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: