clever_title 0.0.4

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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/clever_title.rb +46 -0
  3. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OThmZTk5M2Y0YzdkNTg4M2U4YzU2MTgyMmQyZWEwODlmZTEwYTcwNw==
5
+ data.tar.gz: !binary |-
6
+ ZDgzN2QzMTFhNmZjOTc3ZmVjMWFmYmMwZWYyY2Q3YzBiZmUzNzRlZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGU4OTFkZjY5NGFjNWY5NjY3M2IzZTkyMWM2N2IwOWNhM2Q2YTFiM2RlY2Qx
10
+ YjI0MDk3NDU3Njk4YzE5MGExY2E4NWUzN2VkYjEwNTJjOGY4OGVlYzk4MDRk
11
+ MWVjM2JlOGVhZGE1NDEyYWE3NDMzOGQ2MTk2MjlkYjAyZWY0ZjE=
12
+ data.tar.gz: !binary |-
13
+ MzM2ZmYxNDYwZTM0Y2U2MmRlNmUwZWJlNTA0ODM5MTkyNWRiM2VjYjJiNjZm
14
+ MDZmZGE3MDZkOTVmZWRlZjIxN2M5NTJmMGZkM2U0YWQ3OGY4MmVjZGVlNTk4
15
+ M2M3MzRmZWI5ODQxZmViYjkwOTM4MDM2YTY3YjgzNzk2NmIzNDU=
@@ -0,0 +1,46 @@
1
+ module CleverTitle
2
+ attr_accessor :title, :max_downcase_conversion, :capitalize_first_letter
3
+ @@conjunctions = %w(and or but nor so for yet after although long as because before even if even though if once provided since that though till unless until what when whenever wherever whether while)
4
+
5
+ @@prepositions = %w(aboard about above across after against along amid among anti around as at before behind below beneath beside besides between beyond but by concerning considering despite down during except excepting excluding following for from in inside into like minus near of off on onto opposite outside over past per plus regarding round save since than through to toward towards under underneath unlike until up upon versus via with within without)
6
+
7
+ def clever_title args = {}
8
+ @title = self
9
+ @max_downcase_conversion = 4
10
+ @max_downcase_conversion = args[:max_downcase_conversion] if args[:max_downcase_conversion]
11
+ @capitalize_first_letter = true unless args[:capitalize_first_letter] == false
12
+ self.run
13
+ @title
14
+ end
15
+
16
+ protected
17
+
18
+ def run
19
+ capitalise
20
+ # lower_conjunctions
21
+ lower_words
22
+ capitalise_first_word if @capitalize_first_letter
23
+ end
24
+
25
+ def capitalise
26
+ @title = @title.split.map(&:capitalize).join(' ')
27
+ end
28
+
29
+ def lower_words
30
+ all_words = (@@conjunctions << @@prepositions).flatten!
31
+ all_words = all_words.uniq
32
+ words_to_filter = all_words
33
+ words_to_filter = all_words.select { |x| x if x.length <= @max_downcase_conversion } if @max_downcase_conversion
34
+ words = @title.split
35
+ fixed = words.map { |w| if words_to_filter.include? w.downcase then w.downcase! else w end }
36
+ @title = fixed.join ' '
37
+ end
38
+
39
+ def capitalise_first_word
40
+ @title = @title.slice(0,1).upcase + @title.slice(1..-1)
41
+ end
42
+
43
+ def seperate_words
44
+ @title.split(/\W+/)
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clever_title
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Mitch Stanley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Clever_title is a simple attempt to capitalise title's correctly. This
14
+ includes keeping prepositions, articles or conjunctions lower case and keeping acronyms
15
+ uppercase.
16
+ email: mitch@fastmail.co.uk
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/clever_title.rb
22
+ homepage: http://rubygems.org/gems/clever_title
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.5
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: A more accurate way of handling titles
46
+ test_files: []