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

- (Node) initialize(name = nil, attrs = {})



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

- (Object) fields

Returns the value of attribute fields



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

def fields
  @fields
end

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

- (Object) object

Returns the value of attribute object



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

def object
  @object
end

Class Method Details

+ (Object) first_response(obj, *method_names)



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

+ (Object) make_name(obj)



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

- (Object) to_s



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

def to_s
  quote( name )
end

- (Object) to_str



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

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