Class: Utopia::Basename

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, extension = false) ⇒ Basename

A basename represents a file name with an optional extension. You can specify a specific extension to identify or specify true to select any extension after the last trailing dot.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/utopia/path.rb', line 24

def initialize(name, extension = false)
	if extension
		if extension == true
			offset = name.rindex('.')
		else
			offset = name.rindex(extension) - 1
		end
		
		@name = name[0...offset]
		@extension = name[offset+1..-1]
	else
		@name = name
		@extension = nil
	end
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension.



49
50
51
# File 'lib/utopia/path.rb', line 49

def extension
  @extension
end

#nameObject (readonly)

Returns the value of attribute name.



48
49
50
# File 'lib/utopia/path.rb', line 48

def name
  @name
end

Instance Method Details

#localeObject



55
56
57
# File 'lib/utopia/path.rb', line 55

def locale
	parts.last if parts.size > 1
end

#partsObject



51
52
53
# File 'lib/utopia/path.rb', line 51

def parts
	@parts ||= @name.split('.')
end

#rename(name) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/utopia/path.rb', line 40

def rename(name)
	copy = self.dup
	
	copy.send(:instance_variable_set, :@name, name)
	
	return copy
end

#to_sObject



63
64
65
# File 'lib/utopia/path.rb', line 63

def to_s
	to_str
end

#to_strObject



59
60
61
# File 'lib/utopia/path.rb', line 59

def to_str
	"#{name}#{extension}"
end