itrigga-core_ext 1.0.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ Version 1.2.0 Anson 2012/02/06
2
+ * Added recursive_stringify_keys to Hash
data/Gemfile CHANGED
@@ -6,14 +6,20 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  gem "fastercsv", ">= 1.5.4"
9
- gem "bundler", "~> 1.0.0"
9
+ gem "bundler", ">= 1.0.0"
10
10
 
11
11
  group :development do
12
+ gem "rspec", "1.3.0"
13
+ gem "rspec-rails", "1.3.2"
14
+ gem "bundler", ">= 1.0.0"
12
15
  gem "jeweler", "~> 1.6.4"
13
16
  end
14
17
 
15
18
  group :test do
16
19
  gem "rspec", "1.3.0"
17
20
  gem "rspec-rails", "1.3.2"
21
+ gem "bundler", ">= 1.0.0"
22
+ gem "rcov", ">= 0"
23
+ gem "fastercsv", ">= 1.5.4"
18
24
  gem 'test-unit', '1.2.3' # needed by rspec if using ruby 1.9.X
19
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "itrigga-core_ext"
8
- s.version = "1.0.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Al Davidson", "Anson Kelly"]
12
- s.date = "2011-12-07"
12
+ s.date = "2012-02-06"
13
13
  s.description = "Adds methods for \n Hash: \n - symbolize_keys\n - recursive_symbolize_keys\n Array:\n - to_csv (requires FasterCSV gem if ruby 1.8)\n - select_with_index\n - to_auto_complete_list\n - active_record_type_condition_rendering\n "
14
14
  s.email = "aldavidson@itrigga.com"
15
15
  s.extra_rdoc_files = [
@@ -36,7 +36,8 @@ Gem::Specification.new do |s|
36
36
  "pkg/trigga-core_ext-0.1.0.gem",
37
37
  "spec/hash_spec.rb",
38
38
  "spec/spec.opts",
39
- "spec/spec_helper.rb"
39
+ "spec/spec_helper.rb",
40
+ "spec/string_spec.rb"
40
41
  ]
41
42
  s.homepage = "http://gems.itrigga.com/trigga-core_ext"
42
43
  s.licenses = ["MIT"]
@@ -18,6 +18,13 @@ class Hash
18
18
 
19
19
  end
20
20
 
21
+ def recursive_stringify_keys
22
+ inject({}) do |options, (key, value)|
23
+ options[key.to_s] = value.kind_of?(Hash) ? value.recursive_stringify_keys : value
24
+ options
25
+ end
26
+ end
27
+
21
28
 
22
29
  # Allows you to convert a hash to an array suitable for use in an ActiveRecord finder conditions clause
23
30
  #
@@ -44,6 +51,16 @@ class Hash
44
51
  end
45
52
 
46
53
 
54
+ # lets you do :
55
+ # {:simian=>'chimp', :fish=>'trout', :rodent=>'vole'} - [:simian, :fish]
56
+ # => {:rodent=>'vole'}
57
+ def -( *args )
58
+ keys = *args.to_a.flatten
59
+ hash = self.clone
60
+ keys.each{ |k| hash.delete(k) }
61
+ hash
62
+ end
63
+
47
64
  #
48
65
  # The way bindings work in ruby 1.9+ has changed so add this to work for both
49
66
  # 1.8 and 1.9
@@ -9,6 +9,14 @@ class String
9
9
  !!(self =~ /^[-+]?[0-9]([0-9]*)?$/)
10
10
  end
11
11
 
12
+ #
13
+ # How many words are in this string
14
+ # Includes duplicates
15
+ #
16
+ def word_count
17
+ self.to_utf8.scan(/(\w|-|')+/).size
18
+ end
19
+
12
20
  #
13
21
  # Removes starting, trailing whitespace and double spaces
14
22
  #
@@ -41,4 +41,10 @@ describe Hash do
41
41
  end
42
42
  end
43
43
 
44
+ describe "-" do
45
+ it "should remove the requested keys" do
46
+ ({:a=>'a', :b=>'b', :c=>'c'} - [:a,:b]).should == {:c=>'c'}
47
+ end
48
+ end
49
+
44
50
  end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe String do
5
+
6
+ describe "word_count" do
7
+ it "should return 2" do
8
+ "two words".word_count.should == 2
9
+ end
10
+
11
+ it "should handle hypenated words" do
12
+ "one-way street".word_count.should == 2
13
+ end
14
+
15
+ it "should handle possessive apostrophe" do
16
+ "this is max's ball".word_count.should == 4
17
+ end
18
+
19
+ context "when string is a different encoding" do
20
+ it "should not blow up" do
21
+ str = "two &#162words".force_encoding("ISO-8859-1")
22
+ str.valid_encoding?.should == true
23
+ str.word_count.should == 2
24
+ end
25
+ end
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,63 +1,132 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: itrigga-core_ext
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Al Davidson
9
14
  - Anson Kelly
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2011-12-07 00:00:00.000000000Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: fastercsv
17
- requirement: &76326950 !ruby/object:Gem::Requirement
18
+
19
+ date: 2012-03-08 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
23
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 11
28
+ segments:
29
+ - 1
30
+ - 5
31
+ - 4
22
32
  version: 1.5.4
23
- type: :runtime
33
+ name: fastercsv
24
34
  prerelease: false
25
- version_requirements: *76326950
26
- - !ruby/object:Gem::Dependency
27
- name: bundler
28
- requirement: &76326710 !ruby/object:Gem::Requirement
35
+ type: :runtime
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
33
48
  version: 1.0.0
49
+ name: bundler
50
+ prerelease: false
34
51
  type: :runtime
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 27
60
+ segments:
61
+ - 1
62
+ - 3
63
+ - 0
64
+ version: 1.3.0
65
+ name: rspec
35
66
  prerelease: false
36
- version_requirements: *76326710
37
- - !ruby/object:Gem::Dependency
38
- name: jeweler
39
- requirement: &76326470 !ruby/object:Gem::Requirement
67
+ type: :development
68
+ requirement: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
40
71
  none: false
41
- requirements:
72
+ requirements:
73
+ - - "="
74
+ - !ruby/object:Gem::Version
75
+ hash: 31
76
+ segments:
77
+ - 1
78
+ - 3
79
+ - 2
80
+ version: 1.3.2
81
+ name: rspec-rails
82
+ prerelease: false
83
+ type: :development
84
+ requirement: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 23
92
+ segments:
93
+ - 1
94
+ - 0
95
+ - 0
96
+ version: 1.0.0
97
+ name: bundler
98
+ prerelease: false
99
+ type: :development
100
+ requirement: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
42
105
  - - ~>
43
- - !ruby/object:Gem::Version
106
+ - !ruby/object:Gem::Version
107
+ hash: 7
108
+ segments:
109
+ - 1
110
+ - 6
111
+ - 4
44
112
  version: 1.6.4
45
- type: :development
113
+ name: jeweler
46
114
  prerelease: false
47
- version_requirements: *76326470
48
- description: ! "Adds methods for \n Hash: \n - symbolize_keys\n - recursive_symbolize_keys\n
49
- \ Array:\n - to_csv (requires FasterCSV gem if ruby 1.8)\n - select_with_index\n
50
- \ - to_auto_complete_list\n - active_record_type_condition_rendering\n "
115
+ type: :development
116
+ requirement: *id006
117
+ description: "Adds methods for \n Hash: \n - symbolize_keys\n - recursive_symbolize_keys\n Array:\n - to_csv (requires FasterCSV gem if ruby 1.8)\n - select_with_index\n - to_auto_complete_list\n - active_record_type_condition_rendering\n "
51
118
  email: aldavidson@itrigga.com
52
119
  executables: []
120
+
53
121
  extensions: []
54
- extra_rdoc_files:
122
+
123
+ extra_rdoc_files:
55
124
  - LICENSE.txt
56
125
  - README.rdoc
57
- files:
126
+ files:
58
127
  - .rvmrc
128
+ - CHANGELOG.md
59
129
  - Gemfile
60
- - Gemfile.lock
61
130
  - LICENSE.txt
62
131
  - README.rdoc
63
132
  - Rakefile
@@ -75,34 +144,41 @@ files:
75
144
  - spec/hash_spec.rb
76
145
  - spec/spec.opts
77
146
  - spec/spec_helper.rb
147
+ - spec/string_spec.rb
78
148
  homepage: http://gems.itrigga.com/trigga-core_ext
79
- licenses:
149
+ licenses:
80
150
  - MIT
81
151
  post_install_message:
82
152
  rdoc_options: []
83
- require_paths:
153
+
154
+ require_paths:
84
155
  - lib
85
156
  - lib/itrigga
86
157
  - lib/itrigga
87
- required_ruby_version: !ruby/object:Gem::Requirement
158
+ required_ruby_version: !ruby/object:Gem::Requirement
88
159
  none: false
89
- requirements:
90
- - - ! '>='
91
- - !ruby/object:Gem::Version
92
- version: '0'
93
- segments:
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
94
165
  - 0
95
- hash: -124005361
96
- required_rubygems_version: !ruby/object:Gem::Requirement
166
+ version: "0"
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
168
  none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
102
176
  requirements: []
177
+
103
178
  rubyforge_project:
104
- rubygems_version: 1.8.10
179
+ rubygems_version: 1.8.17
105
180
  signing_key:
106
181
  specification_version: 3
107
182
  summary: extensions for core classes Hash, Array
108
183
  test_files: []
184
+
@@ -1,30 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- fastercsv (1.5.4)
5
- git (1.2.5)
6
- hoe (2.12.4)
7
- rake (~> 0.8)
8
- jeweler (1.6.4)
9
- bundler (~> 1.0)
10
- git (>= 1.2.5)
11
- rake
12
- rack (1.1.0)
13
- rake (0.8.7)
14
- rspec (1.3.0)
15
- rspec-rails (1.3.2)
16
- rack (>= 1.0.0)
17
- rspec (>= 1.3.0)
18
- test-unit (1.2.3)
19
- hoe (>= 1.5.1)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- bundler (~> 1.0.0)
26
- fastercsv (>= 1.5.4)
27
- jeweler (~> 1.6.4)
28
- rspec (= 1.3.0)
29
- rspec-rails (= 1.3.2)
30
- test-unit (= 1.2.3)