Class: Nanaimo::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/nanaimo/object.rb

Overview

An object that belongs to a plist.

Direct Known Subclasses

Array, Data, Dictionary, QuotedString, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, annotation) ⇒ Object

Returns a new instance of Object.


15
16
17
18
19
20
# File 'lib/nanaimo/object.rb', line 15

def initialize(value, annotation)
  self.value = value
  self.annotation = annotation

  raise 'Item cannot be initialize with a nil value' if value.nil?
end

Instance Attribute Details

#annotationString

Returns The annotation comment.

Returns:

  • (String)

    The annotation comment


13
14
15
# File 'lib/nanaimo/object.rb', line 13

def annotation
  @annotation
end

#valueObject

Returns The underlying native Ruby value.

Returns:

  • The underlying native Ruby value


9
10
11
# File 'lib/nanaimo/object.rb', line 9

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object


36
37
38
39
40
41
42
43
44
45
# File 'lib/nanaimo/object.rb', line 36

def <=>(other)
  other_value = if other.is_a?(Object)
                  other.value
                elsif other.is_a?(value.class)
                  other
                end
  return unless other_value

  value <=> other_value
end

#==(other) ⇒ Object Also known as: eql?


22
23
24
25
26
27
28
29
# File 'lib/nanaimo/object.rb', line 22

def ==(other)
  return unless other
  if other.is_a?(self.class)
    other.value == value && annotation == other.annotation
  elsif other.is_a?(value.class)
    other == value
  end
end

#as_rubyObject

Returns A native Ruby object representation.

Returns:

  • A native Ruby object representation


53
54
55
# File 'lib/nanaimo/object.rb', line 53

def as_ruby
  raise 'unimplemented'
end

#hashObject


32
33
34
# File 'lib/nanaimo/object.rb', line 32

def hash
  value.hash
end

#to_sObject


47
48
49
# File 'lib/nanaimo/object.rb', line 47

def to_s
  format('<%s %s>', self.class, value)
end