Class: SlideField::ObjectData
- Inherits:
-
Object
- Object
- SlideField::ObjectData
- Defined in:
- lib/slidefield/object_data.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#context ⇒ Object
Returns the value of attribute context.
-
#include_path ⇒ Object
Returns the value of attribute include_path.
-
#loc ⇒ Object
readonly
Returns the value of attribute loc.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #<<(child) ⇒ Object
- #[](selector) ⇒ Object
- #ancestor(selector) ⇒ Object
- #context_string ⇒ Object
- #get(var) ⇒ Object
- #has?(var) ⇒ Boolean
-
#initialize(type, loc) ⇒ ObjectData
constructor
A new instance of ObjectData.
- #rules ⇒ Object
- #set(var, val, loc = nil, type = nil) ⇒ Object
- #var_loc(var) ⇒ Object
- #var_type(var) ⇒ Object
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
2 3 4 |
# File 'lib/slidefield/object_data.rb', line 2 def children @children end |
#context ⇒ Object
Returns the value of attribute context.
3 4 5 |
# File 'lib/slidefield/object_data.rb', line 3 def context @context end |
#include_path ⇒ Object
Returns the value of attribute include_path.
3 4 5 |
# File 'lib/slidefield/object_data.rb', line 3 def include_path @include_path end |
#loc ⇒ Object (readonly)
Returns the value of attribute loc.
2 3 4 |
# File 'lib/slidefield/object_data.rb', line 2 def loc @loc end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/slidefield/object_data.rb', line 3 def parent @parent end |
#type ⇒ Object (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_string ⇒ Object
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
12 13 14 |
# File 'lib/slidefield/object_data.rb', line 12 def has?(var) @variables.has_key? var end |
#rules ⇒ Object
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 |