Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/epubforge/core_extensions/string.rb
Instance Method Summary collapse
-
#epf_backhashed_filename ⇒ Object
TODO: Need comprehensive list of characters to be protected.
- #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.
19 20 21 |
# File 'lib/epubforge/core_extensions/string.rb', line 19 def epf_backhashed_filename self.gsub(" ", "\\ ") end |
#epf_camelize ⇒ Object
2 3 4 |
# File 'lib/epubforge/core_extensions/string.rb', line 2 def epf_camelize gsub(/(?:^|_)(.)/) { $1.upcase } end |
#epf_decamelize ⇒ Object
6 7 8 |
# File 'lib/epubforge/core_extensions/string.rb', line 6 def epf_decamelize self.gsub( /([a-z])([A-Z])/ ) { $1.downcase + "_" + $2.downcase }.downcase end |
#epf_deunderscorize_as_title ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/epubforge/core_extensions/string.rb', line 51 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
10 11 12 |
# File 'lib/epubforge/core_extensions/string.rb', line 10 def epf_remove_surrounding_quotes self.gsub(/(^['"]|['"]$)/) end |
#epf_remove_surrounding_quotes! ⇒ Object
14 15 16 |
# File 'lib/epubforge/core_extensions/string.rb', line 14 def epf_remove_surrounding_quotes! self.replace( self.epf_remove_surrounding_quotes ) end |
#epf_titlecap_words ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/epubforge/core_extensions/string.rb', line 23 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(&:fwf_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
39 40 41 |
# File 'lib/epubforge/core_extensions/string.rb', line 39 def epf_underscorize self.downcase.gsub(/\s+/,"_").gsub(/[\W]/,"") end |
#to_pathname ⇒ Object
47 48 49 |
# File 'lib/epubforge/core_extensions/string.rb', line 47 def to_pathname Pathname.new( self ) end |