Class: Alpinist::Profile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, url) ⇒ Profile

Returns a new instance of Profile.



8
9
10
11
12
13
14
15
# File 'lib/alpinist/profile.rb', line 8

def initialize(document, url)
  @document = document
  @url = url
  @root_nodes = []
  @descriptors = {}
  @insubstantial_descriptors = []
  parse!
end

Instance Attribute Details

#root_nodesObject (readonly)

Returns the value of attribute root_nodes.



6
7
8
# File 'lib/alpinist/profile.rb', line 6

def root_nodes
  @root_nodes
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/alpinist/profile.rb', line 6

def url
  @url
end

Instance Method Details

#all_descriptorsObject



32
33
34
# File 'lib/alpinist/profile.rb', line 32

def all_descriptors
  @descriptors.values
end

#find_descriptor(id) ⇒ Object



23
24
25
26
# File 'lib/alpinist/profile.rb', line 23

def find_descriptor(id)
  id = id.sub(/^#/, '')
  @descriptors[id] || @insubstantial_descriptors.find { |descriptor| descriptor.id == id }
end

#find_node(id) ⇒ Object



17
18
19
20
21
# File 'lib/alpinist/profile.rb', line 17

def find_node(id)
  @root_nodes.inject(nil) do |result, root_node|
    result || root_node.find { |node| node.name == id && node.content.reference.nil? }
  end
end

#root_descriptorsObject



28
29
30
# File 'lib/alpinist/profile.rb', line 28

def root_descriptors
  @root_nodes.map(&:content)
end