Skip to content

Added subject status detail #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ su -c 'yum install libxml2-devel'
* Addresses
* Legal form / Legal form ARES id
* Case reference (where company is registered)
* Company status

## Usage

Expand All @@ -39,13 +40,14 @@ subject = RubyARES::Subject.get(27074358)
```
And then:
```ruby
subject => #<RubyARES::Subject:0x00000002502470 @ico=27074358, @ic=27074358, @dic=CZ27074358, @name=Asseco Central Europe, a.s., @company=nil, @status=Aktivní, @addresses=[#<RubyARES::Address:0x000000025026f0 @id=”200015797”, @street=Budějovická, @postcode=14000, @city=Praha, @city_part=Michle, @house_number=778, @house_number_type=”1”, @orientational_number=”3a”>], @updated_at=nil, @legal_form=Akciová společnost, @legal_form_id=121, @case_reference=#<RubyARES::CaseReference:0x00000001e386f8 @place=Městský soud v Praze, @section=”B”, @insert=8525>>
subject => #<RubyARES::Subject:0x00007fe2368f7918 @ico="27074358", @ic="27074358", @dic="CZ27074358", @name="Asseco Central Europe, a.s.", @company=nil, @status="Aktivní", @state=#<RubyARES::State:0x00007fe2368cf620 @state=:active, @bankruptcy=0, @compensation=0, @refusal=0, @liquidation=0>, @addresses=[#<RubyARES::Address:0x00007fe2368ec0b8 @id="209786397", @street="Budějovická", @postcode="14000", @city="Praha", @city_part="Michle", @house_number="778", @house_number_type="1", @orientational_number="3a", @county=nil>], @updated_at=nil, @legal_form="Akciová společnost", @legal_form_id="121", @case_reference=#<RubyARES::CaseReference:0x00007fe2368cf6e8 @place="Městský soud v Praze", @section="B", @insert="8525">>
subject.name => “Asseco Central Europe, a.s.”
subject.ic => “27074358”
subject.address => #<RubyARES::Address:0x000000025026f0 @id=”200015797”, @street=”Budějovická”, @postcode=”14000”, @city=”Praha”, @city_part=”Michle”, @house_number=”778”, @house_number_type=”1”, @orientational_number=”3a”>
subject.address.to_str => “Budějovická 3a/778\n14000 Praha\nMichle\n”
subject.case_reference => #<RubyARES::CaseReference:0x00000001e386f8 @place=”Městský soud v Praze”, @section=”B”, @insert=”8525”>
subject.case_reference.to_str => “Městský soud v Praze B 8525”
subject.state => #<RubyARES::State:0x00007fe2368cf620 @state=:active, @bankruptcy=0, @compensation=0, @refusal=0, @liquidation=0>
```

### Exceptions
Expand Down
3 changes: 2 additions & 1 deletion lib/ruby-ares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
require 'ruby-ares/subject'
require 'ruby-ares/address'
require 'ruby-ares/case_reference'
require 'ruby-ares/state'
require 'ruby-ares/parser'

module RubyARES
VERSION = '0.0.3'
VERSION = '0.0.4'
end
6 changes: 4 additions & 2 deletions lib/ruby-ares/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class Address
:house_number, # Cislo_domovni
:house_number_type, # Typ_cislo_domovni
:orientational_number, # Cislo_orientacni
:postcode # PSC
:postcode, # PSC
:county # Okres

def initialize(id, street, postcode, city, city_part,
house_number, house_number_type, orientational_number)
house_number, house_number_type, orientational_number, county)
@id = id
@street = street
@postcode = postcode
Expand All @@ -21,6 +22,7 @@ def initialize(id, street, postcode, city, city_part,
@house_number = house_number
@house_number_type = house_number_type
@orientational_number = orientational_number
@county = county
end

def to_str
Expand Down
11 changes: 9 additions & 2 deletions lib/ruby-ares/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ def self.get_subject(xml)
place = node.find('//D:SZ/D:SD/D:T').to_a[0].content unless node.find('//D:SZ/D:SD/D:T').to_a.size == 0
record = node.find('//D:SZ/D:OV').to_a[0].content unless node.find('//D:SZ/D:OV').to_a.size == 0
section, insert = record.split if record
state = node.find('//D:SOR/D:SSU').to_a[0].content unless node.find('//D:SOR/D:SSU').to_a.size == 0
bankruptcy = node.find('//D:SOR/D:KKZ/D:K').to_a[0].content unless node.find('//D:SOR/D:KKZ/D:K').to_a.size == 0
compensation = node.find('//D:SOR/D:VY/D:K').to_a[0].content unless node.find('//D:SOR/D:VY/D:K').to_a.size == 0
refusal = node.find('//D:SOR/D:ZAM/D:K').to_a[0].content unless node.find('//D:SOR/D:ZAM/D:K').to_a.size == 0
liquidation = node.find('//D:SOR/D:LI/D:K').to_a[0].content unless node.find('//D:SOR/D:LI/D:K').to_a.size == 0

@case_reference = RubyARES::CaseReference.new(place, section, insert)
@state = RubyARES::State.new(state, bankruptcy, compensation, refusal, liquidation)
end

# Corresponding addresses
Expand All @@ -44,7 +50,7 @@ def self.get_subject(xml)
end

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

protected
Expand All @@ -61,9 +67,10 @@ def self.find_addresses(doc)
house_number = node.find('D:CD').to_a[0].content unless node.find('D:CD').to_a.size == 0
house_number_type = node.find('D:TCD').to_a[0].content unless node.find('D:TCD').to_a.size == 0
orientational_number = node.find('D:CO').to_a[0].content unless node.find('D:CO').to_a.size == 0
county = node.find('D:NOK').to_a[0].content unless node.find('D:NOK').to_a.size == 0

@addresses << RubyARES::Address.new(id, street, postcode, city, city_part,
house_number, house_number_type, orientational_number)
house_number, house_number_type, orientational_number, county)
end

return @addresses
Expand Down
40 changes: 40 additions & 0 deletions lib/ruby-ares/state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# encoding: utf-8

module RubyARES
class State

# mappings source: http://wwwinfo.mfcr.cz/ares/xml_doc/schemas/ares/ares_datatypes/v_1.0.3/ares_datatypes_v_1.0.3.xsd

MAPPINGS_STATE = {
"Aktivní" => :active,
"Zaniklý" => :closed
}.freeze

MAPPINGS_KVZ = {
0 => 'není a nebyl',
1 => 'poslední nastal(-a) před více než rokem od této aktualizace',
2 => 'poslední nastal(-a) před méně než rokem a více než půlrokem od této aktualizace',
3 => 'poslední nastal(-a) před méně než půlrokem od této aktualizace',
4 => 'poslední nastal(-a) právě při této aktualizaci'
}.freeze

attr_reader :state, # Stav
:bankruptcy, # Konkurz
:compensation, # Vyrovnani
:refusal, # Zamitnuti
:liquidation # Likvidace

def initialize(state, bankruptcy, compensation, refusal, liquidation)
@state = MAPPINGS_STATE[state]
@bankruptcy = bankruptcy.to_i
@compensation = compensation.to_i
@refusal = refusal.to_i
@liquidation = liquidation.to_i
end

def self.kvz_to_str(kvz_id)
MAPPINGS_KVZ[kvz_id.to_i]
end

end
end
4 changes: 3 additions & 1 deletion lib/ruby-ares/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Subject
:legal_form,# Pravni forma
:legal_form_id, # Id pravni formy
:status, # Stav
:state, # Stav - podrobneji
:case_reference, # Spisova znacka
:addresses, # Adresy
:updated_at # Datum_zmeny
Expand All @@ -22,11 +23,12 @@ def self.get(ic)
RubyARES::Parser.get_subject xml
end

def initialize(ic, dic, name, status, addresses, updated_at, legal_form, legal_form_id, case_reference)
def initialize(ic, dic, name, status, addresses, updated_at, legal_form, legal_form_id, case_reference, state)
@ic, @ico = ic, ic
@dic = dic
@name, @company = name
@status = status
@state = state
@addresses = addresses
@updated_at = updated_at
@legal_form = legal_form
Expand Down
12 changes: 12 additions & 0 deletions test/test_ares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ def test_case_reference_insert
assert_equal '8525', @subject.case_reference.insert
end

def test_state_active
assert_equal :active, @subject.state.state
end

def test_state_liquidation
assert_equal 0, @subject.state.liquidation
end

def test_state_mappings
assert_equal 'není a nebyl', RubyARES::State.kvz_to_str(@subject.state.liquidation)
end

end
2 changes: 1 addition & 1 deletion test/test_ares_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class RubyARESAddressTest < Minitest::Test

def setup
@address = RubyARES::Address.new(1, 'Kunzova', '10010', 'Brno', 'Královo pole', 1, 1, nil)
@address = RubyARES::Address.new(1, 'Kunzova', '10010', 'Brno', 'Královo pole', 1, 1, nil, nil)
end

def test_address_to_string
Expand Down
20 changes: 20 additions & 0 deletions test/test_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# encoding: UTF-8

require 'minitest/autorun'
require 'ruby-ares/state'

class RubyARESStateTest < Minitest::Test

def setup
@state = RubyARES::State.new("Aktivní", 0, 0, 0, 0)
end

def test_state
assert_equal :active, @state.state
end

def test_mappings
assert_equal 'není a nebyl', RubyARES::State.kvz_to_str(@state.liquidation)
end

end