Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rename2mac/libs.rb

Instance Method Summary collapse

Instance Method Details

#bnObject



27
28
29
# File 'lib/rename2mac/libs.rb', line 27

def bn
	File.basename( self )
end

#dnObject



23
24
25
# File 'lib/rename2mac/libs.rb', line 23

def dn
	File.dirname( self )
end

#escape_globObject

escape [] and {} character for Dir.glob to use



3
4
5
# File 'lib/rename2mac/libs.rb', line 3

def escape_glob
	self.gsub(/([\[\]\{\}\*\?\\])/, '\\\\\1')
end


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rename2mac/libs.rb', line 36

def print_diff
	# highlight the character that is not UTF8-MAC compatible
	print self.dn + '/'
	self.bn.each_char { |c|
		if c.um_different?
			print c.red.bold
		else
			print c
		end
	}
	puts
end

#to_mObject



7
8
9
10
11
12
13
# File 'lib/rename2mac/libs.rb', line 7

def to_m
	# convert string to UTF8-MAC format
	self.encode('UTF8-MAC', 'UTF-8').force_encoding('UTF-8')

	# convert with extra function of replace invalid character to null
	#self.encode('UTF8-MAC', 'UTF-8', invalid: :replace, undef: :replace, replace: '')
end

#to_uObject



15
16
17
18
19
20
21
# File 'lib/rename2mac/libs.rb', line 15

def to_u
	# convert string to UTF-8 format
	self.encode('UTF-8', 'UTF8-MAC')

	# convert with extra function of replace invalid character to null
	#self.encode('UTF-8', 'UTF8-MAC', invalid: :replace, undef: :replace, replace: '')
end

#um_different?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/rename2mac/libs.rb', line 31

def um_different?
	# return if the string is different when converted to UTF8-MAC format
	self.unpack('H*') != self.to_m.unpack('H*')
end