Class: Jats::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/jats/node.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(xml = nil) ⇒ Node
Returns a new instance of Node.
19
20
21
22
|
# File 'lib/jats/node.rb', line 19
def initialize(xml=nil)
@xml = xml
@index = self.class.index_for(type)
end
|
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
17
18
19
|
# File 'lib/jats/node.rb', line 17
def index
@index
end
|
#xml ⇒ Object
Returns the value of attribute xml.
17
18
19
|
# File 'lib/jats/node.rb', line 17
def xml
@xml
end
|
Class Method Details
.from_xml(xml) ⇒ Object
3
4
5
|
# File 'lib/jats/node.rb', line 3
def self.from_xml(xml)
new(xml)
end
|
.index_for(type) ⇒ Object
11
12
13
14
15
|
# File 'lib/jats/node.rb', line 11
def self.index_for(type)
@@_indices ||= {}
@@_indices[type] ||= 0
@@_indices[type] += 1
end
|
.reset_indices ⇒ Object
7
8
9
|
# File 'lib/jats/node.rb', line 7
def self.reset_indices
@@_indices = {}
end
|
Instance Method Details
#attributes ⇒ Object
33
34
35
|
# File 'lib/jats/node.rb', line 33
def attributes
{}
end
|
#name ⇒ Object
Also known as:
id
28
29
30
|
# File 'lib/jats/node.rb', line 28
def name
"#{type}:#{xml['id'] || index}"
end
|
#to_hash ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/jats/node.rb', line 37
def to_hash
{
name => {
type: type,
id: id,
}.merge(attributes)
}
end
|
#type ⇒ Object
24
25
26
|
# File 'lib/jats/node.rb', line 24
def type
self.class.name.split('::').last.downcase
end
|