clever_title 0.0.4 → 0.0.5

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 +9 -9
  2. data/lib/clever_title.rb +46 -2
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OThmZTk5M2Y0YzdkNTg4M2U4YzU2MTgyMmQyZWEwODlmZTEwYTcwNw==
4
+ ZDc5MDM5ZmQ1MWZkZWNhOWM5OGNmMjkxZDY4ODAzYWJmMTRjOWFiMw==
5
5
  data.tar.gz: !binary |-
6
- ZDgzN2QzMTFhNmZjOTc3ZmVjMWFmYmMwZWYyY2Q3YzBiZmUzNzRlZg==
7
- !binary "U0hBNTEy":
6
+ MGU1Y2U2NmVlMTQ4Y2Q2YmU0ZGUxM2Y0NDkwMjEwNTU4NTczOThkZA==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- NGU4OTFkZjY5NGFjNWY5NjY3M2IzZTkyMWM2N2IwOWNhM2Q2YTFiM2RlY2Qx
10
- YjI0MDk3NDU3Njk4YzE5MGExY2E4NWUzN2VkYjEwNTJjOGY4OGVlYzk4MDRk
11
- MWVjM2JlOGVhZGE1NDEyYWE3NDMzOGQ2MTk2MjlkYjAyZWY0ZjE=
9
+ MDVkMjQ2ZDgzOTNiZjlkMjBmNDc1MWQ0MDMwYmQzZDU4NzZjNmJiY2FlYTk4
10
+ ZDg5M2FhM2MwMTBlMTc5MDg2ZmJkZTU2NDA4OWE5NTU3MTgxZTE5YzgzNmE0
11
+ NzllMzY5NDc2MWM3YmE3OTIzOTMwOGQ2YWYzNThjOWYyN2JhMGU=
12
12
  data.tar.gz: !binary |-
13
- MzM2ZmYxNDYwZTM0Y2U2MmRlNmUwZWJlNTA0ODM5MTkyNWRiM2VjYjJiNjZm
14
- MDZmZGE3MDZkOTVmZWRlZjIxN2M5NTJmMGZkM2U0YWQ3OGY4MmVjZGVlNTk4
15
- M2M3MzRmZWI5ODQxZmViYjkwOTM4MDM2YTY3YjgzNzk2NmIzNDU=
13
+ YjAwZjIxNThjYWVlZTY2OTgwNjY0MTEyMDZkYjZhYWUyMjZmOGIyMzJkNzFm
14
+ NzIwMWYxYmM0NDZkODViOTJlZmQ3OWE3Zjk5ODIwMzQwZGQyMWU5MjkwODI0
15
+ MDU0ZjE1M2VjMTRjYmUyMzEwNjQyMDUxNmYwYmJjOGMyZjMzMmM=
data/lib/clever_title.rb CHANGED
@@ -1,31 +1,70 @@
1
+ # A module for more accurate titles
1
2
  module CleverTitle
2
- attr_accessor :title, :max_downcase_conversion, :capitalize_first_letter
3
+ # The string that needs to be title case
4
+ attr_accessor :title
5
+ # The maximum amount of letters to lower case conjunctions and prepositions
6
+ attr_accessor :max_downcase_conversion
7
+ # Whether to capitalise the first letter of the string
8
+ attr_accessor :capitalize_first_letter
9
+ # Capitalize after full stop and atleast 1 space
10
+ attr_accessor :capitalize_after_period
11
+
12
+ # A list of conjunctions for lowercase
3
13
  @@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
14
 
15
+ # A list of prepositions for lowercase
5
16
  @@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
17
 
7
- def clever_title args = {}
18
+ #Call this function on a string to add title case
19
+ #
20
+ #Optionally configure max_downcase_conversion and capitalize_first_letter
21
+ #
22
+ #== Example #1
23
+ #
24
+ # "hello world".clever_title # "Hello World"
25
+ #
26
+ #== Example #2
27
+ #
28
+ # "hello world".clever_title(max_downcase_conversion: 5) # "Hello World"
29
+ def clever_title args = {} # :args: :max_downcase_conversion, :capitalize_first_letter
30
+ @title = self
31
+ @max_downcase_conversion = 4
32
+ @max_downcase_conversion = args[:max_downcase_conversion] if args[:max_downcase_conversion]
33
+ @capitalize_first_letter = true unless args[:capitalize_first_letter] == false
34
+ @capitalize_after_period = true unless args[:capitalize_after_period ] == false
35
+ self.run
36
+ @title
37
+ end
38
+
39
+ # Call this function to replace the current string permanently
40
+ def clever_title! args = {} # :args: :max_downcase_conversion, :capitalize_first_letter
8
41
  @title = self
9
42
  @max_downcase_conversion = 4
10
43
  @max_downcase_conversion = args[:max_downcase_conversion] if args[:max_downcase_conversion]
11
44
  @capitalize_first_letter = true unless args[:capitalize_first_letter] == false
45
+ @capitalize_after_period = true unless args[:capitalize_after_period ] == false
12
46
  self.run
47
+ self.replace(@title)
13
48
  @title
14
49
  end
15
50
 
16
51
  protected
17
52
 
53
+ # Called from the clever_title method to run through functionality
18
54
  def run
19
55
  capitalise
20
56
  # lower_conjunctions
21
57
  lower_words
22
58
  capitalise_first_word if @capitalize_first_letter
59
+ capitalise_after_period if @capitalize_after_period
23
60
  end
24
61
 
62
+ # capitalise each word
25
63
  def capitalise
26
64
  @title = @title.split.map(&:capitalize).join(' ')
27
65
  end
28
66
 
67
+ # Find conjunctions and prepositions that need to be lower case
29
68
  def lower_words
30
69
  all_words = (@@conjunctions << @@prepositions).flatten!
31
70
  all_words = all_words.uniq
@@ -36,9 +75,14 @@ module CleverTitle
36
75
  @title = fixed.join ' '
37
76
  end
38
77
 
78
+ # Capitalise first word in the string
39
79
  def capitalise_first_word
40
80
  @title = @title.slice(0,1).upcase + @title.slice(1..-1)
41
81
  end
82
+ # Capitalise first word after a period
83
+ def capitalise_after_period
84
+ @title = @title.gsub(/(\.(\s+)([a-z]))/) {|word| word.upcase }
85
+ end
42
86
 
43
87
  def seperate_words
44
88
  @title.split(/\W+/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clever_title
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch Stanley
@@ -19,7 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - lib/clever_title.rb
22
- homepage: http://rubygems.org/gems/clever_title
22
+ homepage: https://github.com/acoustep/clever_title
23
23
  licenses:
24
24
  - MIT
25
25
  metadata: {}
@@ -39,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
39
  version: '0'
40
40
  requirements: []
41
41
  rubyforge_project:
42
- rubygems_version: 2.0.5
42
+ rubygems_version: 2.1.2
43
43
  signing_key:
44
44
  specification_version: 4
45
45
  summary: A more accurate way of handling titles