Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/mkwebook/ext/string.rb
Instance Method Summary collapse
- #expa ⇒ Object
- #f ⇒ Object
- #normalize_file_path(force_extname = nil) ⇒ Object
- #normalize_uri(force_extname = nil) ⇒ Object
- #p ⇒ Object
- #relative_path_from(base) ⇒ Object
Instance Method Details
#expa ⇒ Object
8 9 10 |
# File 'lib/mkwebook/ext/string.rb', line 8 def expa File.(self) end |
#f ⇒ Object
12 13 14 |
# File 'lib/mkwebook/ext/string.rb', line 12 def f expa end |
#normalize_file_path(force_extname = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mkwebook/ext/string.rb', line 16 def normalize_file_path(force_extname = nil) return self unless present? uri = URI.parse(self) return unless uri.scheme.in? %w(http https) return unless uri.path.present? file_path = uri.path[1..] extname = force_extname || File.extname(file_path) basename = File.basename(file_path, extname) origin = "#{uri.scheme.try { |s| s + '_' }}#{uri.host}#{uri.port.try { |p| '_' + p.to_s }}" basename += "_#{Digest::MD5.hexdigest(uri.query)}" if uri.query.present? URI.decode_www_form_component(File.join(origin, File.dirname(file_path), basename + extname)) end |
#normalize_uri(force_extname = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/mkwebook/ext/string.rb', line 29 def normalize_uri(force_extname = nil) return self unless present? uri = URI.parse(self) return unless uri.scheme.in? %w(http https) return unless uri.path.present? file_path = uri.path[1..] extname = force_extname || File.extname(file_path) basename = File.basename(file_path, extname) basename += "_#{Digest::MD5.hexdigest(uri.query)}" if uri.query.present? origin = "#{uri.scheme.try { |s| s + '_' }}#{uri.host}#{uri.port.try { |p| '_' + p.to_s }}" file_path = File.join(origin, File.dirname(file_path), basename + extname) if uri.fragment.present? file_path += "##{uri.fragment}" else file_path end end |
#p ⇒ Object
4 5 6 |
# File 'lib/mkwebook/ext/string.rb', line 4 def p puts self end |
#relative_path_from(base) ⇒ Object
47 48 49 |
# File 'lib/mkwebook/ext/string.rb', line 47 def relative_path_from(base) Pathname.new(self).relative_path_from(Pathname.new(base)).to_s.gsub(%r{^\.\./}, '') end |