Class: Vizier::Node

Inherits:
Base show all
Includes:
Support
Defined in:
lib/support/vizier.rb

Constant Summary

Constant Summary

Constants included from Support

Support::LEGAL_CHARS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support

#attributes, #attributes=, included, #legal?, #quote, #sanitize

Methods inherited from Base

#[], #[]=

Constructor Details

#initialize(name = nil, attrs = {}) ⇒ Node

Returns a new instance of Node



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/support/vizier.rb', line 132

def initialize( name = nil, attrs={} )
  self.attributes = attrs
  if name.is_a?( String )
    self.name = name
    @label = attrs.delete(:label) || name
  else
    @object = name
    self.name = Node.make_name( @object )
    @label = attrs.delete(:label) || Node.first_response( @object, :name, :identifier, :label ) || name
  end
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields



129
130
131
# File 'lib/support/vizier.rb', line 129

def fields
  @fields
end

#nameObject

Returns the value of attribute name



130
131
132
# File 'lib/support/vizier.rb', line 130

def name
  @name
end

#objectObject

Returns the value of attribute object



128
129
130
# File 'lib/support/vizier.rb', line 128

def object
  @object
end

Class Method Details

.first_response(obj, *method_names) ⇒ Object



148
149
150
151
# File 'lib/support/vizier.rb', line 148

def self.first_response obj, *method_names
  responder = method_names.flatten.detect { |m| obj.respond_to?(m) }
  obj.send( responder ) unless responder.nil?
end

.make_name(obj) ⇒ Object



144
145
146
# File 'lib/support/vizier.rb', line 144

def self.make_name( obj )
  sanitize [ obj.class, first_response( obj, :name, :identifier, :id, :hash)].join('_')
end

Instance Method Details

#to_sObject



161
162
163
# File 'lib/support/vizier.rb', line 161

def to_s
  quote( name )
end

#to_strObject



157
158
159
# File 'lib/support/vizier.rb', line 157

def to_str
  "#{quote name} #{attributes.to_s};"
end