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.



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

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



11
12
13
# File 'lib/nanaimo/object.rb', line 11

def annotation
  @annotation
end

#valueObject

Returns The underlying native Ruby value.

Returns:

  • The underlying native Ruby value



7
8
9
# File 'lib/nanaimo/object.rb', line 7

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



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

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?



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

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



51
52
53
# File 'lib/nanaimo/object.rb', line 51

def as_ruby
  raise 'unimplemented'
end

#hashObject



30
31
32
# File 'lib/nanaimo/object.rb', line 30

def hash
  value.hash
end

#to_sObject



45
46
47
# File 'lib/nanaimo/object.rb', line 45

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