string-mapper 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.1.1 2009-10-27
2
+ * 1 major enhancement:
3
+ * Map of Regexp with captures to a Proc that receive them as an array. For
4
+ example:
5
+ my_mappings["(.+) and (.+)"] => lambda { |captures|
6
+ "First #{captures[0]} and then #{captures[1]}" }
7
+
1
8
  == 0.1.0 2009-09-30
2
9
 
3
10
  * 1 major enhancement:
data/Rakefile CHANGED
@@ -1,9 +1,3 @@
1
- require 'rubygems'
2
- gem 'hoe', '>= 2.1.0'
3
- require 'hoe'
4
- require 'fileutils'
5
- require 'lib/string-mapper'
6
-
7
1
  require 'spec/rake/spectask'
8
2
 
9
3
  desc 'Run specs for StringMapper.'
@@ -11,17 +5,22 @@ Spec::Rake::SpecTask.new(:default) do |t|
11
5
  t.spec_files = FileList['spec/string-mapper_spec.rb']
12
6
  end
13
7
 
14
- Hoe.plugin :newgem
15
-
16
- $hoe = Hoe.spec 'string-mapper' do
17
- self.summary = 'String extension for conversions based on dynamic mappings'
18
- self.version = StringMapper::VERSION::STRING
19
- self.developer 'Fernando García Samblas', 'fernando.garcia@the-cocktail.com'
20
- self.rubyforge_name = self.name # TODO this is default value
21
- self.extra_deps = [['activesupport','>= 1.2.0']]
22
-
8
+ # gem stuff
9
+ if ENV['BUILDING_NEWGEM']
10
+ require 'rubygems'
11
+ gem 'hoe', '>= 2.1.0'
12
+ require 'hoe'
13
+ require 'fileutils'
14
+ require 'lib/string-mapper'
15
+ require 'newgem/tasks'
16
+
17
+ Hoe.plugin :newgem
18
+
19
+ $hoe = Hoe.spec 'string-mapper' do
20
+ self.summary = 'String extension for conversions based on dynamic mappings'
21
+ self.version = StringMapper::VERSION::STRING
22
+ self.developer 'Fernando García Samblas', 'fernando.garcia@the-cocktail.com'
23
+ self.rubyforge_name = self.name # TODO this is default value
24
+ self.extra_deps = [['activesupport','>= 1.2.0']]
25
+ end
23
26
  end
24
-
25
- require 'newgem/tasks'
26
- Dir['tasks/**/*.rake'].each { |t| load t }
27
-
data/lib/string-mapper.rb CHANGED
@@ -29,14 +29,10 @@ module StringMapper #:nodoc:
29
29
  class VERSION #:nodoc:
30
30
  MAJOR = 0
31
31
  MINOR = 1
32
- TINY = 0
32
+ TINY = 1
33
33
  PATCH = nil # Set to nil for official release
34
34
 
35
35
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
36
-
37
- def to_s
38
- STRING
39
- end
40
36
  end
41
37
  end
42
38
 
@@ -57,7 +53,11 @@ class String
57
53
  mapping = if value.is_a?(String)
58
54
  eval('"'+value+'"')
59
55
  elsif value.is_a?(Proc)
60
- value.call
56
+ if $~.captures.any?
57
+ value.call $~.captures
58
+ else
59
+ value.call
60
+ end
61
61
  else
62
62
  value
63
63
  end
@@ -41,16 +41,21 @@ describe "String.add_mapper(:target)" do
41
41
  end
42
42
 
43
43
  it 'should convert from RegExps using matched captures in the returned value' do
44
- String.target_mappings[/In the (.+) of the (.+)$/i] = '#{$1.downcase}-of-the-#{$2.downcase}'
45
- 'In the Name of the Father'.to_target.should == 'name-of-the-father'
44
+ String.target_mappings[/In the (.+) of the (.+)$/i] = '#{$1.downcase} of #{$2.downcase}'
45
+ 'In the Name of the Father'.to_target.should == 'name of father'
46
46
  end
47
47
 
48
48
  it 'should execute the value if it is a Proc object' do
49
- def new_world_url
50
- '/worlds/new'
51
- end
52
- String.target_mappings['new world'] = lambda { new_world_url }
53
- 'new world'.to_target.should == new_world_url
49
+ String.target_mappings['new world'] = lambda {'for all of us'}
50
+ 'new world'.to_target.should == 'for all of us'
51
+ end
52
+
53
+ it 'should pass matched captures as arguments to the proc object' do
54
+ String.target_mappings["(.+) new (.+)"] = lambda {|captures|
55
+ "This is a #{captures[0]} new #{captures[1]}"
56
+ }
57
+ 'brand new world'.to_target.should == "This is a brand new world"
58
+
54
59
  end
55
60
  end
56
61
 
@@ -1,30 +1,35 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require 'rake'
3
2
 
4
3
  Gem::Specification.new do |s|
5
4
  s.name = %q{string-mapper}
6
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
+
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Fernando García Samblas"]
9
- s.autorequire = %q{string-mapper}
10
- s.date = %q{2009-09-30}
11
- s.email = %q{fernando.garcia@the-cocktail.com}
12
- s.files = ["History.txt", "COPYING", "README.markdown", "Rakefile", "lib/string-mapper.rb", "spec/string-mapper_spec.rb"]
13
- s.homepage = %q{http://github.com/nando/string-mapper}
8
+ s.authors = ["Fernando Garc\303\255a Samblas"]
9
+ s.date = %q{2009-10-27}
10
+ s.description = %q{}
11
+ s.email = ["fernando.garcia@the-cocktail.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
13
+ s.files = ["COPYING", "History.txt", "Manifest.txt", "README.markdown", "Rakefile", "init.rb", "lib/string-mapper.rb", "spec/string-mapper_spec.rb", "string-mapper.gemspec"]
14
+ s.rdoc_options = ["--main", "README.rdoc"]
14
15
  s.require_paths = ["lib"]
15
- s.rubygems_version = %q{1.2.0}
16
+ s.rubyforge_project = %q{string-mapper}
17
+ s.rubygems_version = %q{1.3.5}
16
18
  s.summary = %q{String extension for conversions based on dynamic mappings}
17
19
 
18
20
  if s.respond_to? :specification_version then
19
21
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
20
- s.specification_version = 2
22
+ s.specification_version = 3
21
23
 
22
- if current_version >= 3 then
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
23
25
  s.add_runtime_dependency(%q<activesupport>, [">= 1.2.0"])
26
+ s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
24
27
  else
25
28
  s.add_dependency(%q<activesupport>, [">= 1.2.0"])
29
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
26
30
  end
27
31
  else
28
32
  s.add_dependency(%q<activesupport>, [">= 1.2.0"])
33
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
29
34
  end
30
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Fernando Garc\xC3\xADa Samblas"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-02 00:00:00 +02:00
12
+ date: 2009-10-27 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency