Class: Guide::Node
- Inherits:
-
Object
- Object
- Guide::Node
- Defined in:
- app/models/guide/node.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #can_be_rendered? ⇒ Boolean
- #child_nodes ⇒ Object
- #image_path(image_name, extension = "png") ⇒ Object
-
#initialize(options = {}) ⇒ Node
constructor
A new instance of Node.
- #leaf_node? ⇒ Boolean
- #name ⇒ Object
- #node_type ⇒ Object
- #view_model ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Node
Returns a new instance of Node.
23 24 25 26 |
# File 'app/models/guide/node.rb', line 23 def initialize( = {}) @id = infer_id_from_class_name @options = end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'app/models/guide/node.rb', line 21 def id @id end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'app/models/guide/node.rb', line 21 def @options end |
Class Method Details
.child_node_class(id) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/models/guide/node.rb', line 12 def self.child_node_class(id) child_node_class_name = "#{self}::#{id.to_s.camelize}" child_node_class_name.constantize rescue NameError => name_error raise Guide::Errors::InvalidNode, "I can't build the tree that backs Guide because I could not load the class #{child_node_class_name}.", name_error.backtrace end |
.contains(id, options = {}) ⇒ Object
8 9 10 |
# File 'app/models/guide/node.rb', line 8 def self.contains(id, = {}) child_nodes[id] = child_node_class(id).new() end |
.inherited(sub_class) ⇒ Object
4 5 6 |
# File 'app/models/guide/node.rb', line 4 def self.inherited(sub_class) sub_class.child_nodes = {} end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 |
# File 'app/models/guide/node.rb', line 40 def ==(other) self.class == other.class end |
#can_be_rendered? ⇒ Boolean
49 50 51 |
# File 'app/models/guide/node.rb', line 49 def can_be_rendered? false end |
#child_nodes ⇒ Object
36 37 38 |
# File 'app/models/guide/node.rb', line 36 def child_nodes self.class.child_nodes end |
#image_path(image_name, extension = "png") ⇒ Object
57 58 59 |
# File 'app/models/guide/node.rb', line 57 def image_path(image_name, extension = "png") Guide::Photographer.new(image_name, extension).image_path end |
#leaf_node? ⇒ Boolean
32 33 34 |
# File 'app/models/guide/node.rb', line 32 def leaf_node? self.child_nodes.empty? end |
#name ⇒ Object
28 29 30 |
# File 'app/models/guide/node.rb', line 28 def name @id.to_s.titleize end |
#node_type ⇒ Object
44 45 46 47 |
# File 'app/models/guide/node.rb', line 44 def node_type # for direct children, this will be :node self.class.superclass.name.demodulize.underscore.to_sym end |