smart_case 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03bcc148aecd06dd2f1e8c29788feb2fd2063857
4
- data.tar.gz: 7548826396923cb30cef96a3932ec3194cbcdc47
3
+ metadata.gz: 7a6e289ec9557517f4783010ac04df00d3d2e572
4
+ data.tar.gz: 39adfcc359f7dfcf6bdecff9cb4157533be1c642
5
5
  SHA512:
6
- metadata.gz: f49578b5910b5ade00da6cdc251f94f79cedafb4801ec9799464ea0c8d590ce9b96ec4a3c39bb539458564a070b97c52e4f5d661d87ddcc81ce71625e865823b
7
- data.tar.gz: 7d16efb81e1c3ee207931e04a08d20a1ca6280d3ede42b0016ab74118b91ace517ebf0a5283427c801ab0cc1de5f5c9f1ca55576ca5f934db2262d18d5024b0b
6
+ metadata.gz: b739faaa1d1a0c722b43b18dd8a3386903450047e0dedbcc3d7af189fd44952184204a6b043eba1faf85654880e926a784349138f4083ceb6f73d042f83b57a9
7
+ data.tar.gz: 104c486bfd03c2957ec3e764991d9fd2ff871c9cf20b03356b4fde8bd37797a3a5db953f0a7eaf793d6c8f95a09a452aede62e09468f107acc304f401141a40f
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ smart_case
2
+ ==========
3
+ A while ago came up with the idea that it would be cool if ruby `case` statements accepted blocks for the condition evaluation. `SmartCase` is the result.
4
+
5
+ ### Installation
6
+
7
+ ```bash
8
+ $ gem install smart_case
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ ```ruby
14
+ require 'smart_case'
15
+
16
+ age = gets.chomp.to_i
17
+ smart_case(age) do
18
+ w { |x| x < 20 }
19
+ t { 'You are a teenager.' }
20
+
21
+ w { |x| x >= 20 && x < 30 }
22
+ t { 'You are a young adult' }
23
+
24
+ w { |x| x >= 30 && x < 60 }
25
+ t { |x| "You are an adult of age #{x}" } # Object is accesible via arguments
26
+
27
+ w { |x| x > 60 }
28
+ t ->(x) { 'You are an aged adult' } # `w` and `t` accepts any callable object instead of a block
29
+ end
30
+ => "You are an adult of age 47"
31
+ ```
32
+
33
+ You can use an instance of `SmartCase` too:
34
+
35
+ ```ruby
36
+ sm = SmartCase.new(nil) do # object is optional
37
+ w { |x| x == 2 }
38
+ t { 'Your number is 2!' }
39
+
40
+ w { |x| x == 3 }
41
+ t { 'Your number is 3!' }
42
+ end
43
+
44
+ sm.call 2
45
+ => "Your number is 2!"
46
+ sm.call 3
47
+ => "Your number is 3!"
48
+ sm.call 4
49
+ => nil
50
+
51
+ # Add conditional clauses on the fly
52
+ sm.w { |x| x == 4 }
53
+ sm.t { 'Your number is 4!' }
54
+ sm.call 4
55
+ => "Your number is 4!"
56
+
57
+ # or...
58
+ sm.instance_eval do
59
+ w { |x| x == 5 }
60
+ t { 'Your number is 5!' }
61
+ call 5
62
+ end
63
+ => "Your number is 5!"
64
+ ```
65
+
66
+ ### Contributing to smart_case
67
+ + Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
68
+ + Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
69
+ + Fork the project.
70
+ + Start a feature/bugfix branch.
71
+ + Commit and push until you are happy with your contribution.
72
+ + Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
73
+ + 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.
74
+
75
+ ### Copyright
76
+ Copyright (c) 2013 Nicolas Oga. See LICENSE.txt for
77
+ further details.
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.description = %Q{Better case statements for ruby}
22
22
  gem.email = "2112.oga@gmail.com"
23
23
  gem.authors = ["Nicolas Oga"]
24
- gem.version = '0.0.1'
24
+ gem.version = '0.0.2'
25
25
  # dependencies defined in Gemfile
26
26
  end
27
27
  Jeweler::RubygemsDotOrgTasks.new
data/lib/smart_case.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class SmartCase
2
- def initialize(o)
2
+ def initialize(o = nil)
3
3
  @o, @when, @then = o, [], []
4
4
  instance_eval(&Proc.new) if block_given?
5
5
  self
data/smart_case.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "smart_case"
8
- s.version = "0.0.1"
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 = ["Nicolas Oga"]
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.email = "2112.oga@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  "Gemfile",
23
23
  "Gemfile.lock",
24
24
  "LICENSE.txt",
25
- "README.rdoc",
25
+ "README.md",
26
26
  "Rakefile",
27
27
  "lib/smart_case.rb",
28
28
  "lib/version.rb",
@@ -1,17 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe SmartCase do
4
- it "succeeds" do
4
+ it 'succeeds' do
5
5
  c = SmartCase.new(2) do
6
6
  w { |x| x == 2 }
7
- t { "Your number is 2!" }
7
+ t { 'Your number is 2!' }
8
8
 
9
9
  w { |x| x == 3 }
10
- t { "Your number is 3!" }
10
+ t { 'Your number is 3!' }
11
11
  end
12
12
 
13
- expect(c.call).to eq("Your number is 2!")
14
- expect(c.call(3)).to eq("Your number is 3!")
13
+ expect(c.call).to eq('Your number is 2!')
14
+ expect(c.call(3)).to eq('Your number is 3!')
15
+ end
16
+
17
+ it 'accepts procs' do
18
+ c = SmartCase.new(2) do
19
+ w ->(x) { x == 2 }
20
+ t ->(x) { 'Your number is 2!' }
21
+
22
+ w ->(x) { x == 3 }
23
+ t ->(x) { 'Your number is 3!' }
24
+ end
25
+
26
+ expect(c.call).to eq('Your number is 2!')
27
+ expect(c.call(3)).to eq('Your number is 3!')
15
28
  end
16
29
 
17
30
  it 'integrates into Kernel' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Oga
@@ -72,14 +72,14 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files:
74
74
  - LICENSE.txt
75
- - README.rdoc
75
+ - README.md
76
76
  files:
77
77
  - .document
78
78
  - .rspec
79
79
  - Gemfile
80
80
  - Gemfile.lock
81
81
  - LICENSE.txt
82
- - README.rdoc
82
+ - README.md
83
83
  - Rakefile
84
84
  - lib/smart_case.rb
85
85
  - lib/version.rb
data/README.rdoc DELETED
@@ -1,19 +0,0 @@
1
- = smart_case
2
-
3
- Description goes here.
4
-
5
- == Contributing to smart_case
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * 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.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2013 Nicolas Oga. See LICENSE.txt for
18
- further details.
19
-