Class: SpaceObject::Base

Inherits:
ActiveSupport::OrderedHash
  • Object
show all
Defined in:
lib/space_object/base.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/space_object/base.rb', line 6

def [](key)
  key = convert_key!(key)
  unless key[' ']
    super(key)
  else
    first_key = key[/^[^ ]+/]
    value = self[first_key]

    return nil if hash.nil?
    rest_keys = key[(first_key.length + 1)..-1]
    value[rest_keys]
  end
end

#[]=(key, value) ⇒ Object Also known as: store



20
21
22
23
24
25
26
27
28
29
# File 'lib/space_object/base.rb', line 20

def []=(key, value)
  key = convert_key!(key)
  unless key[' ']
    super(key, convert_value!(value))
  else
    first_key = key[/^[^ ]+/]
    value = (self[first_key] ||= self.class.new)
    value[(first_key.length + 1)..-1] = value
  end
end

#default(key = nil) ⇒ Object



33
34
35
# File 'lib/space_object/base.rb', line 33

def default(key = nil)
  super(key ? convert_key!(key) : nil)
end

#default=(val) ⇒ Object



37
38
39
# File 'lib/space_object/base.rb', line 37

def default=(val)
  super(key ? convert_key!(key) : nil)
end

#fetch(key, *extras) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/space_object/base.rb', line 41

def fetch(key, *extras)
  key = convert_key!(key)
  first_key = key[/^[^ ]+/]

  value = self[first_key]
  if key[' '].nil? || hash.nil?
    super(key, *extras)
  else
    value.fetch(first_key, *extras)
  end
end