Class: String

Inherits:
Object show all
Defined in:
lib/core_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#epf_backhashed_filenameObject

TODO: Need comprehensive list of characters to be protected.



11
12
13
# File 'lib/core_extensions/string.rb', line 11

def epf_backhashed_filename
  self.gsub(" ", "\\ ")  
end

#epf_blank?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/core_extensions/string.rb', line 2

def epf_blank?
  self.strip.length == 0  
end

#epf_camelizeObject



6
7
8
# File 'lib/core_extensions/string.rb', line 6

def epf_camelize
  gsub(/(?:^|_)(.)/) { $1.upcase }
end

#epf_deunderscorize_as_titleObject



44
45
46
47
48
49
50
51
52
# File 'lib/core_extensions/string.rb', line 44

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_titlecap_wordsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/core_extensions/string.rb', line 15

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
  debugger if self.match( /ii/i )

  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_underscorizeObject



32
33
34
# File 'lib/core_extensions/string.rb', line 32

def epf_underscorize
  self.downcase.gsub(/\s+/,"_").gsub(/[\W]/,"")
end

#to_pathnameObject

def fwf_filepath

EpubForge::FunWith::Files::FilePath.new(self)

end



40
41
42
# File 'lib/core_extensions/string.rb', line 40

def to_pathname
  Pathname.new( self )
end