Class: Estreet::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loc = nil) ⇒ Node

Returns a new instance of Node.



6
7
8
# File 'lib/estreet/node.rb', line 6

def initialize(loc=nil)
  @source_location = loc
end

Instance Attribute Details

#source_locationObject (readonly)

Returns the value of attribute source_location.



4
5
6
# File 'lib/estreet/node.rb', line 4

def source_location
  @source_location
end

Instance Method Details

#as_jsonObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/estreet/node.rb', line 19

def as_json
  attributes.map {|k,v|
    case v
    when Estreet::Node
      [k, v.as_json]
    when Array
      [k, v.map(&:as_json)]
    else
      [k, v]
    end
  }.to_h
  # raise NotImplementedError
end

#loc(source_location) ⇒ Object



10
11
12
13
# File 'lib/estreet/node.rb', line 10

def loc(source_location)
  @source_location = loc # TODO: construct the thing
  self # suitable for chaining
end

#typeObject



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

def type
  self.class.name.gsub(/\AEstreet::/, '')
end