class SlideField::ObjectRules::Base
Public Class Methods
get()
click to toggle source
# File lib/slidefield/object_rules.rb, line 60 def self.get if instance = @@cache[self] instance else instance = self.new instance.rules @@cache[self] = instance end end
new()
click to toggle source
# File lib/slidefield/object_rules.rb, line 13 def initialize @properties = [] @children = [] end
Public Instance Methods
accepted_children()
click to toggle source
# File lib/slidefield/object_rules.rb, line 51 def accepted_children @children.collect {|hash| hash[:type] } end
default_value(name)
click to toggle source
# File lib/slidefield/object_rules.rb, line 46 def default_value(name) rule = @properties.select {|hash| hash[:name] == name }.first rule[:default] if rule end
matching_properties(type)
click to toggle source
# File lib/slidefield/object_rules.rb, line 41 def matching_properties(type) matches = @properties.select {|hash| hash[:type] == type } matches.collect {|hash| hash[:name] } end
optional_properties()
click to toggle source
# File lib/slidefield/object_rules.rb, line 31 def optional_properties required = @properties.select {|hash| !hash[:default].nil? } required.collect {|hash| hash[:name] } end
properties_names()
click to toggle source
# File lib/slidefield/object_rules.rb, line 18 def properties_names @properties.collect {|hash| hash[:name] } end
properties_types()
click to toggle source
# File lib/slidefield/object_rules.rb, line 22 def properties_types @properties.collect {|hash| hash[:type] }.uniq end
required_properties()
click to toggle source
# File lib/slidefield/object_rules.rb, line 26 def required_properties required = @properties.select {|hash| hash[:default].nil? } required.collect {|hash| hash[:name] } end
requirements_of_child(type)
click to toggle source
# File lib/slidefield/object_rules.rb, line 55 def requirements_of_child(type) rule = @children.select {|hash| hash[:type] == type }.first rule[:requirements] if rule end
rules()
click to toggle source
# File lib/slidefield/objects/_base.rb, line 3 def rules child :include child :debug end
type_of_property(name)
click to toggle source
# File lib/slidefield/object_rules.rb, line 36 def type_of_property(name) rule = @properties.select {|hash| hash[:name] == name }.first rule[:type] if rule end
Protected Instance Methods
child(type, min = 0, max = 0)
click to toggle source
# File lib/slidefield/object_rules.rb, line 75 def child(type, min = 0, max = 0) @children << {:type=>type, :requirements=>[min, max]} end
property(name, type, default = nil)
click to toggle source
# File lib/slidefield/object_rules.rb, line 71 def property(name, type, default = nil) @properties << {:name=>name, :type=>type, :default=>default} end