Class: Prune::PObjects::PName

Inherits:
Base
  • Object
show all
Defined in:
lib/prune/p_objects/p_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#indent!, #outdent!, #space, #value_to_s

Constructor Details

#initialize(name) ⇒ PName

Initialize.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/prune/p_objects/p_name.rb', line 9

def initialize(name)
  case name
  when String
    @name = "/" + name
  when Symbol
    @name = "/" + name.to_s
  else
    raise PNameTypeError
  end
  @name.freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/prune/p_objects/p_name.rb', line 6

def name
  @name
end

Instance Method Details

#==(value) ⇒ Object

Compare the value of string.



33
34
35
36
# File 'lib/prune/p_objects/p_name.rb', line 33

def ==(value)
  false if value.instance_of?(self.class)
  @name == value.name
end

#eql?(value) ⇒ Boolean

Compare as a key of hash.

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/prune/p_objects/p_name.rb', line 27

def eql?(value)
  false if value.instance_of?(self.class)
  @name.eql?(value.name)
end

#hashObject

Calculate hash value for PName.



22
23
24
# File 'lib/prune/p_objects/p_name.rb', line 22

def hash
  @name.hash
end

#to_sObject

Convert content to string.



39
40
41
# File 'lib/prune/p_objects/p_name.rb', line 39

def to_s
  @name
end