abn_lookup 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88b2f5ee46fcac8095fabc91f3204768760578a2282aa95b767c630fdac42acb
4
- data.tar.gz: c269d4d2a27ce0cd230d7184cd010609d489d0f1d1e3aa953f215631ea077467
3
+ metadata.gz: 276141b6aaae5383c076b6b2ab7a17536a56e38c296fab584e6ed27873c94ef7
4
+ data.tar.gz: ab311bca6af0587a06811776a387898d4d40d082d5c89891784b071fe343f79c
5
5
  SHA512:
6
- metadata.gz: 8c279bacccf4c10a39c04fa639e4096c7ea20753bd4f800a4b1f5b5b2948ebedc7d4f8b26013dc28f369be8a1354ed21906d2a35d17ffa38a6413d591d41e647
7
- data.tar.gz: c1725dce55ba5c6bfe86e69a50172449d6e7911d8de29dc1c52691feeb40225618ca437b090c9a42d3b67b33bf8c8184bc458f40e9af54fa13f649555ae9b0aa
6
+ metadata.gz: 696b8cf8190be707c30acd77ddf990d1ca17197f32514304488b457ef7511651b6487f265ccf30af2d2f04858309f774c720776f381d4680b330b57a90ef2e3d
7
+ data.tar.gz: 74f09efa50d894a986dd906dd601151f0f51d73103e4824f08a245a679b820c92de84cdefbcf3916a262c6a1e5d54c2c122198356dd4818cf61d12d0d5406304
@@ -0,0 +1,31 @@
1
+ module AbnLookup
2
+ class Abn
3
+ attr_accessor :abn, :abn_status, :abn_status_effective_from, :acn, :address_date,
4
+ :address_postcode, :address_state, :business_name, :entity_name,
5
+ :entity_type_code, :entity_type_name, :gst, :message
6
+
7
+ def active?
8
+ abn_status == "Active"
9
+ end
10
+
11
+ def inspect
12
+ "#<#{self.class.name}:0x#{object_id} @abn=\"#{abn}\" @acn=\"#{acn}\" @active=\"#{active?}\" @gst=\"#{gst}\" @entity_name=\"#{entity_name}}\""
13
+ end
14
+
15
+ def self.parse(data)
16
+ abn = Abn.new
17
+
18
+ # Transforming PascalCase to snake_case
19
+ snake_case = data.each_with_object({}) do |(key, value), new_hash|
20
+ new_key = key.to_s.gsub(/([A-Z])/, '_\1').downcase
21
+ new_hash[new_key.sub(/^_/, '').to_sym] = value
22
+ end
23
+
24
+ snake_case.each do |key, value|
25
+ abn.send("#{key}=", value) if abn.respond_to?("#{key}=")
26
+ end
27
+
28
+ abn
29
+ end
30
+ end
31
+ end
@@ -9,7 +9,7 @@ module AbnLookup
9
9
  raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
10
10
  raise AbnNotFoundError if body["Abn"].empty?
11
11
 
12
- AbnFormatter.formatter(body)
12
+ Abn.parse(body)
13
13
  end
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module AbnLookup
9
9
  raise InvalidGuidError if body["Message"] == "The GUID entered is not recognised as a Registered Party"
10
10
  raise AbnNotFoundError if body["Abn"].empty?
11
11
 
12
- AbnFormatter.formatter(body)
12
+ Abn.parse(body)
13
13
  end
14
14
  end
15
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbnLookup
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/abn_lookup.rb CHANGED
@@ -6,7 +6,7 @@ require "abn_lookup/client"
6
6
  require "abn_lookup/search_by_abn"
7
7
  require "abn_lookup/search_by_acn"
8
8
  require "abn_lookup/search_by_name"
9
- require "abn_lookup/abn_formatter"
9
+ require "abn_lookup/abn"
10
10
  require "abn_lookup/abn_not_found_error"
11
11
  require "abn_lookup/invalid_guid_error"
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abn_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lairton Mendes
@@ -52,7 +52,7 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/abn_lookup.rb
55
- - lib/abn_lookup/abn_formatter.rb
55
+ - lib/abn_lookup/abn.rb
56
56
  - lib/abn_lookup/abn_not_found_error.rb
57
57
  - lib/abn_lookup/add_parameter.rb
58
58
  - lib/abn_lookup/callback_parser.rb
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AbnLookup
4
- class AbnFormatter
5
- def self.formatter(body)
6
- hash = {
7
- abn: body["Abn"],
8
- abn_status: body["AbnStatus"],
9
- abn_status_effective_from: body["AbnStatusEffectiveFrom"],
10
- acn: body["Acn"],
11
- address_date: body["AddressDate"],
12
- address_postcode: body["AddressPostcode"],
13
- address_state: body["AddressState"],
14
- business_name: body["BusinessName"],
15
- entity_name: body["EntityName"],
16
- entity_type_code: body["EntityTypeCode"],
17
- entity_type_name: body["EntityTypeName"],
18
- gst: body["Gst"],
19
- message: body["Message"]
20
- }
21
-
22
- # build Struct
23
- abn = Struct.new(*hash.keys)
24
-
25
- # converting hash to struct
26
- abn.new(*hash.values)
27
- end
28
- end
29
- end