Class: Ssource::Source::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/ssource/source/element.rb

Direct Known Subclasses

Klass, Method, Variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Element

Returns a new instance of Element.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ssource/source/element.rb', line 8

def initialize(json)
  @name = json['name']
  @accessibility = json['accessibility']
  @kind = json['kind']

  @offset = json['offset']
  @length = json['length']
  @name_offset = json['nameoffset']
  @name_length = json['namelength']
  @body_offset = json['bodyoffset']
  @body_length = json['bodylength']

  @elements = json.fetch('substructure', []).reduce([]) do |arr, structure|
    arr << Factory.build(structure)
  end
end

Instance Attribute Details

#accessibilityObject (readonly)

Returns the value of attribute accessibility.



4
5
6
# File 'lib/ssource/source/element.rb', line 4

def accessibility
  @accessibility
end

#body_lengthObject (readonly)

Returns the value of attribute body_length.



6
7
8
# File 'lib/ssource/source/element.rb', line 6

def body_length
  @body_length
end

#body_offsetObject (readonly)

Returns the value of attribute body_offset.



6
7
8
# File 'lib/ssource/source/element.rb', line 6

def body_offset
  @body_offset
end

#elementsObject (readonly)

Returns the value of attribute elements.



4
5
6
# File 'lib/ssource/source/element.rb', line 4

def elements
  @elements
end

#kindObject (readonly)

Returns the value of attribute kind.



4
5
6
# File 'lib/ssource/source/element.rb', line 4

def kind
  @kind
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/ssource/source/element.rb', line 6

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ssource/source/element.rb', line 4

def name
  @name
end

#name_lengthObject (readonly)

Returns the value of attribute name_length.



6
7
8
# File 'lib/ssource/source/element.rb', line 6

def name_length
  @name_length
end

#name_offsetObject (readonly)

Returns the value of attribute name_offset.



6
7
8
# File 'lib/ssource/source/element.rb', line 6

def name_offset
  @name_offset
end

#offsetObject (readonly)

Returns the value of attribute offset.



6
7
8
# File 'lib/ssource/source/element.rb', line 6

def offset
  @offset
end

Instance Method Details

#display_nameObject



25
26
27
# File 'lib/ssource/source/element.rb', line 25

def display_name
  name
end

#pretty_printObject



33
34
35
# File 'lib/ssource/source/element.rb', line 33

def pretty_print
  display_name
end

#to_hashObject



29
30
31
# File 'lib/ssource/source/element.rb', line 29

def to_hash
  { 'name' => display_name }
end