Class: RubyARES::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-ares/parser.rb

Defined Under Namespace

Classes: ARESDatabaseError, ParseError

Class Method Summary collapse

Class Method Details

.get_subject(xml) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby-ares/parser.rb', line 13

def self.get_subject(xml)
  begin
    doc = self.parse_document xml

    # Basic info
    doc.find('//D:VBAS').each do |node|
      attrs = node.children()

      # Attributes of the subject
      @status = node.find("D:ROR/D:SOR/D:SSU").to_a[0].content unless node.find('D:ROR/D:SOR/D:SSU').to_a.size == 0
      @ic = node.find('D:ICO').to_a[0].content unless node.find('D:ICO').to_a.size == 0
      @dic = node.find('D:DIC').to_a[0].content unless node.find('D:DIC').to_a.size == 0
      @name = node.find('D:OF').to_a[0].content unless node.find('D:OF').to_a.size == 0
      @legal_form = node.find('D:PF/D:NPF').to_a[0].content unless node.find('D:PF/D:NPF').to_a.size == 0
    end

    # Corresponding addresses
    @addresses = self.find_addresses doc
  rescue
    raise ParseError, "Can't parse the given document."
  end

  if doc.find('//D:E').to_a.size > 0
    raise ARESDatabaseError, 'ARES returned an error.'
  end

  # Create and return subject
  return RubyARES::Subject.new(@ic, @dic, @name, @status, @addresses, @updated_at, @legal_form)
end