Class: Codetree::Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/codetree.rb

Instance Attribute Summary collapse

Virtual Scopeors collapse

Instance Method Summary collapse

Constructor Details

#initialize(_options = { :type => :defn, :ancestors => [], :scope => :none, :name => "", :line => 0 }) ⇒ Operator

Returns a new instance of Operator.



17
18
19
20
21
22
23
# File 'lib/codetree.rb', line 17

def initialize(_options = { :type =>  :defn, :ancestors => [], :scope => :none, :name =>  "", :line => 0 })
  @type = _options[:type] || :defn
  @ancestors = _options[:ancestors] || []
  @scope = _options[:scope] || :none
  @name = _options[:name] || ""
  @line = _options[:line] || 0
end

Instance Attribute Details

#ancestorsObject (readonly)

Returns the value of attribute ancestors.



12
13
14
# File 'lib/codetree.rb', line 12

def ancestors
  @ancestors
end

#lineObject (readonly)

Returns the value of attribute line.



14
15
16
# File 'lib/codetree.rb', line 14

def line
  @line
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/codetree.rb', line 15

def name
  @name
end

#scopeObject

Returns the value of attribute scope.



13
14
15
# File 'lib/codetree.rb', line 13

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/codetree.rb', line 11

def type
  @type
end

Instance Method Details

#ancestorObject



27
28
29
# File 'lib/codetree.rb', line 27

def ancestor
  return @ancestors.last
end

#renderObject



35
36
37
38
39
40
41
42
43
# File 'lib/codetree.rb', line 35

def render
  return name.to_s if self.ancestors == []
  case type
  when :defn then return "##{name.to_s}"
  when :defs then return ".#{name.to_s}"
  when :class then return "::#{name.to_s}"
  when :module then return "::#{name.to_s}"
  end
end