Class: String
Instance Method Summary collapse
-
#epf_backhashed_filename ⇒ Object
TODO: Need comprehensive list of characters to be protected.
- #epf_blank? ⇒ Boolean
- #epf_camelize ⇒ Object
- #epf_decamelize ⇒ Object
- #epf_deunderscorize_as_title ⇒ Object
- #epf_remove_surrounding_quotes ⇒ Object
- #epf_remove_surrounding_quotes! ⇒ Object
- #epf_titlecap_words ⇒ Object
- #epf_underscorize ⇒ Object
-
#to_pathname ⇒ Object
def fwf_filepath EpubForge::FunWith::Files::FilePath.new(self) end.
Instance Method Details
#epf_backhashed_filename ⇒ Object
TODO: Need comprehensive list of characters to be protected.
23 24 25 |
# File 'lib/core_extensions/string.rb', line 23 def epf_backhashed_filename self.gsub(" ", "\\ ") end |
#epf_blank? ⇒ Boolean
2 3 4 |
# File 'lib/core_extensions/string.rb', line 2 def epf_blank? self.strip.length == 0 end |
#epf_camelize ⇒ Object
6 7 8 |
# File 'lib/core_extensions/string.rb', line 6 def epf_camelize gsub(/(?:^|_)(.)/) { $1.upcase } end |
#epf_decamelize ⇒ Object
10 11 12 |
# File 'lib/core_extensions/string.rb', line 10 def epf_decamelize self.gsub( /([a-z])([A-Z])/ ) { $1.downcase + "_" + $2.downcase }.downcase end |
#epf_deunderscorize_as_title ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/core_extensions/string.rb', line 55 def epf_deunderscorize_as_title words = self.split("_") words = [words[0].capitalize] + words[1..-1].map{|w| TITLE_WORDS_NOT_CAPITALIZED.include?(w) ? w : w.capitalize } words.join(" ") end |
#epf_remove_surrounding_quotes ⇒ Object
14 15 16 |
# File 'lib/core_extensions/string.rb', line 14 def epf_remove_surrounding_quotes self.gsub(/(^['"]|['"]$)/) end |
#epf_remove_surrounding_quotes! ⇒ Object
18 19 20 |
# File 'lib/core_extensions/string.rb', line 18 def epf_remove_surrounding_quotes! self.replace( self.epf_remove_surrounding_quotes ) end |
#epf_titlecap_words ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/core_extensions/string.rb', line 27 def epf_titlecap_words nocaps = %w(a and at be but in is nor of or so teh the to with) upcase = %w(Ii Ii: Iii M.d.) # TODO: ick words = self.downcase.gsub(/\u00a0/, ' ').split(/(\s|\n)+/).map(&:strip).delete_if(&:epf_blank?) first_word = true for word in words word.capitalize! unless nocaps.include?(word) && first_word == false # note: if the word is all caps, will downcase # TODO: What about M.D., state abbreviations, etc.? This is far from perfect. word.upcase! if upcase.include?(word) first_word = false end words.join(" ") end |
#epf_underscorize ⇒ Object
43 44 45 |
# File 'lib/core_extensions/string.rb', line 43 def epf_underscorize self.downcase.gsub(/\s+/,"_").gsub(/[\W]/,"") end |
#to_pathname ⇒ Object
def fwf_filepath
EpubForge::FunWith::Files::FilePath.new(self)
end
51 52 53 |
# File 'lib/core_extensions/string.rb', line 51 def to_pathname Pathname.new( self ) end |