abn_lookup 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17c443ef9e5e1f5a64ceb9f5023c6b63c7d5a8e9ac961ce036f69437e121c610
4
- data.tar.gz: a0a8d4179f01dc7334d109f9369205e60933dbaa35c7cab65f67ad93383a8a01
3
+ metadata.gz: 276141b6aaae5383c076b6b2ab7a17536a56e38c296fab584e6ed27873c94ef7
4
+ data.tar.gz: ab311bca6af0587a06811776a387898d4d40d082d5c89891784b071fe343f79c
5
5
  SHA512:
6
- metadata.gz: d82d72f531b739b24c986bde8c2917ebe1415253410f8144ac765af36bc3a1ce011dd992f8956b0b4461f84c869c0683969bc7309ae465c0d31eb3924d3c8cfb
7
- data.tar.gz: b8b2bff6356f5e9cf3843b894b51892e181d4fb940ba90e5f562f6a911e10a9eddafef1e7bf08f172330824034ccbeb4dd10bb2fd4a00bebdcfb5043cc083ef7
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.2.0"
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.2.0
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