symbolizify 0.1.0

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in symbolizify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Joshua Kovach
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Symbolizify
2
+
3
+ Converts the given string to a symbol-style symbol.
4
+
5
+ This is intended to be a kind of inverse of `#humanize`, but a little more robust than [dehumanize](https://github.com/AndyObtiva/dehumanize). This is a strong symbolizer, converting hyphens, non-standard characters, spaces, camelcase, etc. to underscored strings. The main inspiration for this came after finding that `#dehumanize` did not support dehumanizing strings containing numbers, e.g.
6
+
7
+ ```ruby
8
+ "Abstract Object 1".dehumanize # => "abstract_object1", not "abstract_object_1"
9
+ ```
10
+
11
+ In fact, `dehumanize` was the inspiration, and the overall design of the gem was inspired by this prior art.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'symbolizify', '>= 0.1.0'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install symbolizify
26
+
27
+ ## Usage
28
+
29
+ Call symbolizify on any string to turn it into a symbol-style string! Removes non-word/non-digit characters (except for ! and ? if it's at the end of the string), reduces everything to lowercase with underscores separating things, e.g.
30
+
31
+ ```ruby
32
+ 'Personal Phone'.symbolizify # => 'personal_phone',
33
+ 'Home address'.symbolizify # => 'home_address',
34
+ 'HatRack'.symbolizify # => 'hat_rack',
35
+ 'Who is _why?'.symbolizify # => 'who_is_why?',
36
+ 'Person 1'.symbolizify # => 'person_1',
37
+ 'Personel! #231'.symbolizify # => 'personel_231',
38
+ 'Shekibobo is great!'.symbolizify # => 'shekibobo_is_great!'
39
+ 'test.subject@example.com'.symbolizify # => 'test_subject_example_com'
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module Symbolizify
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ require "symbolizify/version"
2
+ require "active_support/inflector"
3
+
4
+ module ActiveSupport::Inflector
5
+ def symbolizify(s)
6
+ s.titleize.parameterize('_') << s.strip[-1].match(/[!?]/).to_s
7
+ end
8
+ end
9
+
10
+ class String
11
+ def symbolizify
12
+ ActiveSupport::Inflector.symbolizify(self)
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rspec'
13
+
14
+ RSpec.configure do |config|
15
+ config.color_enabled = true
16
+ config.formatter = 'documentation'
17
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'symbolizify'
3
+
4
+ describe String do
5
+ describe "#symbolizify" do
6
+ {
7
+ 'Personal Phone' => 'personal_phone',
8
+ 'Home address' => 'home_address',
9
+ 'HatRack' => 'hat_rack',
10
+ 'Who is _why?' => 'who_is_why?',
11
+ 'Person 1' => 'person_1',
12
+ 'Personel! #231' => 'personel_231',
13
+ 'Shekibobo is great!' => 'shekibobo_is_great!',
14
+ 'test.subject@example.com' => 'test_subject_example_com'
15
+ }.each do |original, symbolizified|
16
+ it "should turn '#{original}' to '#{symbolizified}'" do
17
+ original.symbolizify.should eq symbolizified
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'symbolizify/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "symbolizify"
8
+ gem.version = Symbolizify::VERSION
9
+ gem.authors = ["Joshua Kovach"]
10
+ gem.email = ["kovach.jc@gmail.com"]
11
+ gem.description = %q{Converts any string into a symbol-style symbol.}
12
+ gem.summary = %q{Adds a method `#symbolizify` on ActiveSupport::Inflector and String which converts a string into a symbol-style string.}
13
+ gem.homepage = "https://www.github.com/shekibobo/symbolizify"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency "activesupport", ">= 3.0.0"
20
+ gem.add_development_dependency 'rspec', '~> 2.5'
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symbolizify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joshua Kovach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.5'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.5'
46
+ description: Converts any string into a symbol-style symbol.
47
+ email:
48
+ - kovach.jc@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/symbolizify.rb
59
+ - lib/symbolizify/version.rb
60
+ - spec/spec_helper.rb
61
+ - spec/symbolizify_spec.rb
62
+ - symbolizify.gemspec
63
+ homepage: https://www.github.com/shekibobo/symbolizify
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Adds a method `#symbolizify` on ActiveSupport::Inflector and String which
87
+ converts a string into a symbol-style string.
88
+ test_files:
89
+ - spec/spec_helper.rb
90
+ - spec/symbolizify_spec.rb