titleize 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d23bd4aaf4922bbfdbba7ad91b0bd57daa75168b
4
- data.tar.gz: e93492421eb2d77d6c800a84fad3e48149d0f9f3
3
+ metadata.gz: a22d9670a598846e39d7c526c837f7cdce61c52f
4
+ data.tar.gz: b15abf18dc19969e8949f0e97a18c89b448c0828
5
5
  SHA512:
6
- metadata.gz: 589bf779b36bc2054b8ff5f16fbd9143f9acd3fd09a554107c3148e148b638a811ee31d8c17ecc1f833408e9bb84e468454734aa09765bfb2f3a68f394442807
7
- data.tar.gz: 225be00a67a79bd7e7a0a630e8af2794137dfef719c553c202502086e45fb68c10f4b14e68f02501b16a9c1a25b7be574d350f8f5b64e476bb56940bacb65b03
6
+ metadata.gz: a7485617fdce1fbca51b6d0805bd0de6eaf76659fcff39e31160e50e08a5be5e1e4805baf37915f61f21812f2d6f09c62c079f6ca687d832980c8ecd9bc3cb82
7
+ data.tar.gz: 2c58e24dd98c6607b964caaaabeb8ad77e52e7efc6ec9de1f7b014d12e0b2e9a33a4aaff7b617a8673c234d28b9746e5b006a15bf9a6951b6babb7d055d278a0
@@ -1,3 +1,8 @@
1
+ === 1.4.1 / 2016-09-16
2
+
3
+ * fix capitalization of repeated small words
4
+ * handle multiple punctuated small words ("v.", "vs.")
5
+
1
6
  === 1.4.0 / 2016-02-04
2
7
 
3
8
  * check for the presence of ActiveSupport::Inflector instead of just ActiveSupport [Connor Prussin]
@@ -23,7 +23,7 @@ module Titleize
23
23
 
24
24
  phrases(title).map do |phrase|
25
25
  words = phrase.split
26
- words.map do |word|
26
+ words.map.with_index do |word, index|
27
27
  def word.capitalize
28
28
  # like String#capitalize, but it starts with the first letter
29
29
  self.sub(/[[:alpha:]].*/) {|subword| subword.capitalize}
@@ -40,10 +40,12 @@ module Titleize
40
40
  word
41
41
  when /^[[:digit:]]/ # first character is a number
42
42
  word
43
- when words.first, words.last
44
- word.capitalize
45
43
  when *(SMALL_WORDS + SMALL_WORDS.map {|small| small.capitalize })
46
- word.downcase
44
+ if index == 0 || index == words.size - 1
45
+ word.capitalize
46
+ else
47
+ word.downcase
48
+ end
47
49
  else
48
50
  word.capitalize
49
51
  end
@@ -56,18 +58,22 @@ module Titleize
56
58
  # "simple title" # => ["simple title"]
57
59
  # "more complicated: titling" # => ["more complicated:", "titling"]
58
60
  def phrases(title)
59
- phrases = title.scan(/.+?(?:[:.;?!] |$)/).map {|phrase| phrase.strip }
60
-
61
- # rejoin phrases that were split on the '.' from a small word
62
- if phrases.size > 1
63
- phrases[0..-2].each_with_index do |phrase, index|
64
- if SMALL_WORDS.include?(phrase.split.last.downcase)
65
- phrases[index] << " " + phrases.slice!(index + 1)
66
- end
67
- end
61
+ phrases = [[]]
62
+ title.split.each do |word|
63
+ phrases.last << word
64
+ phrases << [] if ends_with_punctuation?(word) && !small_word?(word)
68
65
  end
66
+ phrases.reject(&:empty?).map { |phrase| phrase.join " " }
67
+ end
68
+
69
+ private
70
+
71
+ def small_word?(word)
72
+ SMALL_WORDS.include? word.downcase
73
+ end
69
74
 
70
- phrases
75
+ def ends_with_punctuation?(word)
76
+ word =~ /[:.;?!]$/
71
77
  end
72
78
  end
73
79
 
@@ -1,3 +1,3 @@
1
1
  module Titleize
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -50,6 +50,7 @@ describe Titleize do
50
50
  phrases("this vs. that. no").should == ["this vs. that.", "no"]
51
51
  phrases("this: that vs. him. no. why?").should ==
52
52
  ["this:", "that vs. him.", "no.", "why?"]
53
+ phrases("this vs. that vs. what").should == ["this vs. that vs. what"]
53
54
  end
54
55
 
55
56
  it "should handle punctuation combined with a small word as the last word" do
@@ -89,6 +90,12 @@ describe Titleize do
89
90
  end
90
91
  end
91
92
 
93
+ it "does not capitalize later uses of the first small word" do
94
+ SMALL_WORDS.each do |word|
95
+ titleize("#{word} and #{word} are different").should == "#{word.capitalize} and #{word} Are Different"
96
+ end
97
+ end
98
+
92
99
  it "should capitalize a small word if it is the last word" do
93
100
  SMALL_WORDS.each do |word|
94
101
  titleize("small #{word}").should == "Small #{word.capitalize}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titleize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Hollingworth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-05 00:00:00.000000000 Z
11
+ date: 2016-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: 1.3.6
76
76
  requirements: []
77
77
  rubyforge_project: titleize
78
- rubygems_version: 2.2.2
78
+ rubygems_version: 2.6.6
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Adds String#titleize for creating properly capitalized titles.