Class: SlideField::ObjectData

Inherits:
Object
  • Object
show all
Defined in:
lib/slidefield/object_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, loc) ⇒ ObjectData

Returns a new instance of ObjectData.



5
6
7
8
9
10
# File 'lib/slidefield/object_data.rb', line 5

def initialize(type, loc)
  @type = type
  @loc = loc
  @variables = {}
  @children = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



2
3
4
# File 'lib/slidefield/object_data.rb', line 2

def children
  @children
end

#contextObject

Returns the value of attribute context.



3
4
5
# File 'lib/slidefield/object_data.rb', line 3

def context
  @context
end

#include_pathObject

Returns the value of attribute include_path.



3
4
5
# File 'lib/slidefield/object_data.rb', line 3

def include_path
  @include_path
end

#locObject (readonly)

Returns the value of attribute loc.



2
3
4
# File 'lib/slidefield/object_data.rb', line 2

def loc
  @loc
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/slidefield/object_data.rb', line 3

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/slidefield/object_data.rb', line 2

def type
  @type
end

Instance Method Details

#<<(child) ⇒ Object



47
48
49
50
# File 'lib/slidefield/object_data.rb', line 47

def <<(child)
  child.parent = self
  @children << child
end

#[](selector) ⇒ Object



52
53
54
# File 'lib/slidefield/object_data.rb', line 52

def [](selector)
  @children.select {|o| o.type == selector }
end

#ancestor(selector) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/slidefield/object_data.rb', line 56

def ancestor(selector)
  p = @parent
  while p
    return p if p.type == selector
    p = p.parent
  end
  nil
end

#context_stringObject



65
66
67
68
69
70
71
72
73
# File 'lib/slidefield/object_data.rb', line 65

def context_string
  array = [@context]
  parent = @parent
  while parent
    array.unshift parent.context unless array.first == parent.context
    parent = parent.parent
  end
  "[#{array.join '] ['}]"
end

#get(var) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/slidefield/object_data.rb', line 23

def get(var)
  if has? var
    @variables[var][1]
  elsif parent
    parent.get var
  end
end

#has?(var) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/slidefield/object_data.rb', line 12

def has?(var)
  @variables.has_key? var
end

#rulesObject



75
76
77
# File 'lib/slidefield/object_data.rb', line 75

def rules
  SlideField::ObjectRules[@type]
end

#set(var, val, loc = nil, type = nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/slidefield/object_data.rb', line 16

def set(var, val, loc = nil, type = nil)
  loc ||= var_loc var
  type ||= var_type var

  @variables[var] = [type, val, loc]
end

#var_loc(var) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/slidefield/object_data.rb', line 39

def var_loc(var)
  if has? var
    @variables[var][2] 
  elsif parent
    parent.var_loc var
  end
end

#var_type(var) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/slidefield/object_data.rb', line 31

def var_type(var)
  if has? var
    @variables[var][0] 
  elsif parent
    parent.var_type var
  end
end