Class: TentClient::TentType

Inherits:
Object
  • Object
show all
Defined in:
lib/tent-client/tent_type.rb

Constant Summary collapse

ALL =
'all'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil) ⇒ TentType

Returns a new instance of TentType.



8
9
10
11
# File 'lib/tent-client/tent_type.rb', line 8

def initialize(uri = nil)
  @version = 0
  parse_uri(uri) if uri
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



7
8
9
# File 'lib/tent-client/tent_type.rb', line 7

def base
  @base
end

#fragmentObject

Returns the value of attribute fragment.



7
8
9
# File 'lib/tent-client/tent_type.rb', line 7

def fragment
  @fragment
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/tent-client/tent_type.rb', line 7

def version
  @version
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/tent-client/tent_type.rb', line 41

def ==(other)
  unless TentType === other
    if String === other
      other = TentType.new(other)
    else
      return false
    end
  end

  base == other.base && version == other.version && has_fragment? == other.has_fragment? && fragment == other.fragment
end

#all?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/tent-client/tent_type.rb', line 13

def all?
  base == ALL
end

#has_fragment?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/tent-client/tent_type.rb', line 17

def has_fragment?
  !!@fragment_separator
end

#to_s(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/tent-client/tent_type.rb', line 30

def to_s(options = {})
  return base if all?

  options[:encode_fragment] = true unless options.has_key?(:encode_fragment)
  if (!has_fragment? && options[:fragment] != true) || options[:fragment] == false
    "#{base}/v#{version}"
  else
    "#{base}/v#{version}##{options[:encode_fragment] ? encode_fragment(fragment) : fragment}"
  end
end