headingify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd7969833778861cc551085dfbe3ac56fb12910f
4
+ data.tar.gz: 4c797dfe295a5894fe0764c22f2c101b2b2c1a4d
5
+ SHA512:
6
+ metadata.gz: 738d8051b28d6b99ea89e68234ee81b4d41e041d83f23b11915aeba6967af3e116747ec1974ebb58d6e74e9b2bf406cd5aade5e9dcdda75881bb17d73203ad94
7
+ data.tar.gz: 27077477d9340025330f22c84bf6f6d3da4f4278a88ac3c7f01e340f8722a9f093cbd9f737b9a6d88868d15fe182e7f8b2bfb8ff89e7cac6409f7b5bd6356991
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in headingify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chris Calo
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.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = Headingify
2
+
3
+ A method used to convert a string into a heading. It extends the String class; currently only supporting the English language. Please contribute if you are adept in other languages utilizing articles, conjuctions, and prepositions.
4
+
5
+ Headingify is based off of grammatical rules set forth in The Chicago Manual of Style. ed. 16 pgf. 8.155.
6
+
7
+ == Download and Installation
8
+
9
+ The latest version of Headingify can be installed with RubyGems:
10
+
11
+ % [sudo] gem install headingify
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'headingify'
16
+
17
+ == Usage
18
+
19
+ To execute in standalone mode do the following:
20
+
21
+ % headingify "a simple string, including the preposition 'with'."
22
+ > A Simple String, including the Preposition 'with'.
23
+
24
+ To escape words in a string do the following:
25
+
26
+ % headingify "folding of the \%CheY\% protein."
27
+ > Folding of the CheY Protein.
28
+
29
+ Headingify works on the String class, and can also be used in code:
30
+
31
+ s = "a simple string, including the preposition 'with'.".headingify
32
+ title = "folding of the \%CheY\% protein."; title.headingify!
33
+
34
+ == License
35
+
36
+ Headingify is released under the MIT license:
37
+
38
+ * http://www.opensource.org/licenses/MIT
39
+
40
+ == Contributing
41
+
42
+ 1. Fork it (https://github.com/vulcancreative/headingify/fork)
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/headingify ADDED
@@ -0,0 +1,23 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'headingify'
4
+
5
+ # print help by default
6
+ if ARGV.length == 0
7
+ print Headingify.help
8
+ end
9
+
10
+ ARGV.each_with_index do |s, i|
11
+ if s =~ /-*h$/ || s =~ /-*help$/
12
+ print Headingify.help
13
+ elsif s =~ /-*v$/ || s =~ /-*version$/
14
+ t = "#{Headingify::TITLE}"
15
+ v = "#{Headingify::VERSION}"
16
+ u = "(#{Headingify::UPDATE} revision #{Headingify::REVISION})"
17
+ print "#{t}, #{v} #{u}\n"
18
+ elsif i == 0
19
+ print s.headingify + "\n"
20
+ else
21
+ print Headingify.help
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'headingify/info'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "headingify"
8
+ s.version = Headingify::VERSION
9
+ s.authors = ["Chris Calo"]
10
+ s.email = ["ccalo@vulcanca.com"]
11
+ s.summary = "A method used to convert a string into a heading."
12
+ s.description = "#{s.summary} It extends String class; English only."
13
+ s.homepage = "http://vulcanca.com"
14
+ s.license = "MIT"
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.required_ruby_version = '>= 1.9.3'
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "bundler", "~> 1.7"
24
+ s.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,76 @@
1
+ class String
2
+ def headingify
3
+ #
4
+ # built to syntactically supercede String.[titlecase|titleize]
5
+ #
6
+ # example : "garlic is as \%GOOD\% as ten mothers"
7
+ # yields : "Garlic Is as GOOD as Ten Mothers"
8
+ #
9
+ # based on rules in The Chicago Manual of Style: ed. 16 pgf. 8.155
10
+ # inspired by http://titlecapitalization.com/
11
+ # © 2014 Copyright Chris Calo. Vulcan Creative, LLC.
12
+ #
13
+
14
+ # http://en.wikipedia.org/wiki/English_articles
15
+ articles = %w[a an the]
16
+
17
+ # http://en.wikipedia.org/wiki/Conjunction_(grammar)
18
+ conjunctions = %w[and but or nor for yet so]
19
+
20
+ # http://en.wikipedia.org/wiki/List_of_English_prepositions
21
+ prepositions = %w[a abaft aboard about above absent across afore after
22
+ against along alongside amid amidst among amongst an anenst apropos
23
+ apud around as aside astride at athwart atop barring before behind
24
+ below beneath beside besides between beyond but by circa concerning
25
+ despite down during except excluding failing following for forenenst
26
+ from given in including inside into like mid midst minus modulo near
27
+ nigh next notwithstanding of off on onto opposite out outside over
28
+ pace past per plus pro qua regarding round sans save since than through
29
+ thru throughout thruout til till times to toward towards under
30
+ underneath unlike until unto up upon versus via vice vis-a-vis
31
+ vis-à-vis with within without worth]
32
+
33
+ # combine for ease of iteration
34
+ blacklist = (articles + conjunctions + prepositions).uniq!
35
+
36
+ # prepare initial string for modification
37
+ working = self.split
38
+
39
+ # determines whether word has quoting characters, or not
40
+ include_open_quote = lambda do |w|
41
+ q = %w[' " ’ ‘ “ ”]
42
+
43
+ return true if q.include?(w[0]) || q.include?(w[w.length - 1])
44
+ return false
45
+ end
46
+
47
+ # capitalize only what's necessary
48
+ working.each_with_index do |(s), i|
49
+ working[i] = /\\%(.*)\\%/.match(s)[1] if s.include?("\%")
50
+ next if s =~ /^o'.*$/
51
+ if blacklist.include?(s) && i == 0; s.capitalize!; next; end
52
+ blacklist.include?(s) ? s.downcase! : s.capitalize!
53
+
54
+ if include_open_quote.call(s)
55
+ open = /^(["'‘“’”])([a-zA-Z]*)(["'‘“’”])?([\.\?!])?$/.match(s)[1]
56
+ temp = /^(["'‘“’”])([a-zA-Z]*)(["'‘“’”])?([\.\?!])?$/.match(s)[2]
57
+ last = /^(["'‘“’”])([a-zA-Z]*)(["'‘“’”])?([\.\?!])?$/.match(s)[3]
58
+ punc = /^(["'‘“’”])([a-zA-Z]*)(["'‘“’”])?([\.\?!])?$/.match(s)[4]
59
+
60
+ unless temp.nil?
61
+ blacklist.include?(temp) ? temp.downcase! : temp.capitalize!
62
+ temp = open + temp unless open.nil?
63
+ temp = temp + last unless last.nil?
64
+ temp = temp + punc unless punc.nil?
65
+ working[i] = temp
66
+ end
67
+ end
68
+ end
69
+
70
+ working.join(" ")
71
+ end
72
+
73
+ def headingify!
74
+ replace self.headingify
75
+ end
76
+ end
@@ -0,0 +1,21 @@
1
+ module Headingify
2
+ TITLE = "Ruby String.headingify Core Extension"
3
+ VERSION = "0.0.1"
4
+ UPDATE = "2014-11-19"
5
+ REVISION = "4"
6
+ USAGE = "headingify \"string\" | \"an \\%ESCAPED\\% string\""
7
+ EXAMPLE_INPUT = "\"garlic is as \\%GOOD\\% as ten mothers\""
8
+ EXAMPLE_OUTPUT = "Garlic Is as GOOD as Ten Mothers"
9
+
10
+ def self.usage
11
+ "Usage: #{USAGE}"
12
+ end
13
+
14
+ def self.example
15
+ "input : #{EXAMPLE_INPUT}\nyield : #{EXAMPLE_OUTPUT}"
16
+ end
17
+
18
+ def self.help
19
+ "#{Headingify.usage}\n\n#{Headingify.example}\n"
20
+ end
21
+ end
data/lib/headingify.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'headingify/info'
2
+ require 'headingify/core_ext/string'
3
+
4
+ module Headingify
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Headingify do
4
+ it "should return the input String as a proper title" do
5
+ input = ["i'm dale, but you have to call me dragon.",
6
+ "i swear, i'm so pissed off at my mom.",
7
+ "as soon as she's of age, i'm putting her in a home.",
8
+ "i'm fucking miserable. i had to get up at 10 o'clock this morning!",
9
+ "why are you so sweaty? i was watching cops.",
10
+ "dad, what are you doing? it's 'shark week'!",
11
+ "i want to roll you into a little ball and shove you up my vagina.",
12
+ "i traveled 500 miles to give you my seed!",
13
+ "a simple string, including the preposition 'with'."]
14
+
15
+ output = ["I'm Dale, but You Have to Call Me Dragon.",
16
+ "I Swear, I'm so Pissed off at My Mom.",
17
+ "As Soon as She's of Age, I'm Putting Her in a Home.",
18
+ "I'm Fucking Miserable. I Had to Get up at 10 o'clock This Morning!",
19
+ "Why Are You so Sweaty? I Was Watching Cops.",
20
+ "Dad, What Are You Doing? It's 'Shark Week'!",
21
+ "I Want to Roll You into a Little Ball and Shove You up My Vagina.",
22
+ "I Traveled 500 Miles to Give You My Seed!",
23
+ "A Simple String, including the Preposition 'with'."]
24
+
25
+ input.each_with_index do |s, i|
26
+ expect(s.headingify).to eq(output[i])
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ require 'headingify'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: headingify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Calo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A method used to convert a string into a heading. It extends String class;
56
+ English only.
57
+ email:
58
+ - ccalo@vulcanca.com
59
+ executables:
60
+ - headingify
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.rdoc
68
+ - Rakefile
69
+ - bin/headingify
70
+ - headingify.gemspec
71
+ - lib/headingify.rb
72
+ - lib/headingify/core_ext/string.rb
73
+ - lib/headingify/info.rb
74
+ - spec/headingify_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: http://vulcanca.com
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.9.3
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A method used to convert a string into a heading.
100
+ test_files:
101
+ - spec/headingify_spec.rb
102
+ - spec/spec_helper.rb