class Nanoc::Identifier
Public Class Methods
from(obj)
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 40 def self.from(obj) case obj when Nanoc::Identifier obj when String Nanoc::Identifier.new(obj) else raise NonCoercibleObjectError.new(obj) end end
new(string, type: :full)
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 51 def initialize(string, type: :full) @type = type case @type when :legacy @string = "/#{string}/".gsub(/^\/+|\/+$/, '/').freeze when :full if string !~ /\A\// raise InvalidIdentifierError.new(string) end @string = string.dup.freeze else raise InvalidTypeError.new(@type) end end
Public Instance Methods
+(other)
click to toggle source
@return [String]
# File lib/nanoc/base/entities/identifier.rb, line 107 def +(other) to_s + other end
<=>(other)
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 85 def <=>(other) to_s <=> other.to_s end
==(other)
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 67 def ==(other) case other when Nanoc::Identifier, String to_s == other.to_s else false end end
Also aliased as: eql?
=~(other)
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 81 def =~(other) Nanoc::Int::Pattern.from(other).match?(to_s) ? 0 : nil end
chop()
click to toggle source
@return [String]
# File lib/nanoc/base/entities/identifier.rb, line 102 def chop to_s.chop end
components()
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 164 def components res = to_s.split('/') if res.empty? [] else res[1..-1] end end
ext()
click to toggle source
@return [String] The extension, without a leading dot.
# File lib/nanoc/base/entities/identifier.rb, line 135 def ext unless full? raise UnsupportedLegacyOperationError end s = File.extname(@string) s && s[1..-1] end
exts()
click to toggle source
@return [Array] List of extensions, without a leading dot.
# File lib/nanoc/base/entities/identifier.rb, line 155 def exts unless full? raise UnsupportedLegacyOperationError end s = File.basename(@string) s ? s.split('.', -1).drop(1) : [] end
full?()
click to toggle source
@return [Boolean] True if this is a full-type identifier (i.e. includes
the extension), false otherwise
# File lib/nanoc/base/entities/identifier.rb, line 91 def full? @type == :full end
hash()
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 77 def hash self.class.hash ^ to_s.hash end
inspect()
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 181 def inspect "<Nanoc::Identifier type=#{@type} #{to_s.inspect}>" end
legacy?()
click to toggle source
@return [Boolean] True if this is a legacy identifier (i.e. does not
include the extension), false otherwise
# File lib/nanoc/base/entities/identifier.rb, line 97 def legacy? @type == :legacy end
prefix(string)
click to toggle source
@return [Nanoc::Identifier]
# File lib/nanoc/base/entities/identifier.rb, line 112 def prefix(string) if string !~ /\A\// raise InvalidPrefixError.new(@string) end Nanoc::Identifier.new(string.sub(/\/+\z/, '') + @string, type: @type) end
to_s()
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 173 def to_s @string end
to_str()
click to toggle source
# File lib/nanoc/base/entities/identifier.rb, line 177 def to_str @string end
without_ext()
click to toggle source
@return [String]
# File lib/nanoc/base/entities/identifier.rb, line 120 def without_ext unless full? raise UnsupportedLegacyOperationError end extname = File.extname(@string) if !extname.empty? @string[0..-extname.size - 1] else @string end end
without_exts()
click to toggle source
@return [String]
# File lib/nanoc/base/entities/identifier.rb, line 145 def without_exts extname = exts.join('.') if !extname.empty? @string[0..-extname.size - 2] else @string end end