justimmo_client 0.6.5 → 0.6.6

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
  SHA1:
3
- metadata.gz: e3c0287a3d5ad70f78d68e3a1ab8b749af95c2b2
4
- data.tar.gz: 9da6e21aa9e182aa670ffc7e6c6d50819efbc007
3
+ metadata.gz: 4af966499684afea9e28c2dacb01816d618c4fe3
4
+ data.tar.gz: 77b692e3404c61651985609698a80ab77867fa17
5
5
  SHA512:
6
- metadata.gz: 8df8d3e790b0ebcfe9060f55fe551547bdb490e964202a1fbbfb64e2500ae0a0505cde9c938655d145592749587a20f961872f580867101849a6da820ca6ebc8
7
- data.tar.gz: 2065f47036e1b8f821141250611b2c70a7820dc637da6b92036b9e823b06580ef413f7584209da235d2ecbb701e14280e0fbd7d91898ba1b77cf03ee2479a55b
6
+ metadata.gz: 43f05f744a4496eb025f13e65f1993052c3c7e8e5cebc9fe7dfbaa6ec5497ec6e4bd34a0dca35aeb7dd73d357ce5c518e641998467968128c55966e9c211e21c
7
+ data.tar.gz: '0385a7d9afde08ada26e6f1aa8576765fecd46f19b903eef3e0ab09f2a84bcca15c2b15a170e685b391c4ca08430ca30c7a8d175f9c146380882fabdacaa6bcd'
@@ -16,24 +16,44 @@ module JustimmoClient::V1
16
16
  # @!group Instance Method Summary
17
17
 
18
18
  def initialize(**options)
19
- @country = find_country(options[:name])
20
- return unless @country
21
- options.update(name: @country.name, alpha2: @country.alpha2, alpha3: @country.alpha3)
22
19
  super(options)
20
+ find_country(options[:name])
21
+ find_country(options[:alpha3])
22
+ find_country(options[:alpha2])
23
+ @name = @country&.name
24
+ @alpha3 = @country&.alpha3
25
+ @alpha2 = @country&.alpha2
23
26
  end
24
27
 
25
28
  def alpha2=(code)
26
- @alpha2 ||= @country.alpha2
29
+ find_country(code)
30
+ @alpha2 ||= @country&.alpha2
27
31
  end
28
32
 
29
33
  def alpha3=(code)
30
- @alpha3 ||= @country.alpha3
34
+ find_country(code)
35
+ @alpha3 ||= @country&.alpha3
36
+ end
37
+
38
+ def name=(country_name)
39
+ find_country(country_name)
40
+ @name ||= @country&.name
31
41
  end
32
42
 
33
43
  def to_s
34
44
  name
35
45
  end
36
46
 
47
+ def to_h
48
+ attributes
49
+ end
50
+
51
+ def to_json(options = nil)
52
+ to_h.to_json(options)
53
+ end
54
+
55
+ alias as_json to_json
56
+
37
57
  def inspect
38
58
  "#<#{self.class} #{self}>"
39
59
  end
@@ -41,11 +61,14 @@ module JustimmoClient::V1
41
61
  private
42
62
 
43
63
  def find_country(name_or_code)
44
- if name_or_code.size <= 3
45
- IsoCountryCodes.find(name_or_code)
46
- else
47
- IsoCountryCodes.search_by_name(name_or_code)
48
- end
64
+ return if name_or_code.nil?
65
+
66
+ @country ||=
67
+ if name_or_code.size <= 3
68
+ IsoCountryCodes.find(name_or_code)
69
+ else
70
+ IsoCountryCodes.search_by_name(name_or_code).first
71
+ end
49
72
  rescue IsoCountryCodes::UnknownCodeError
50
73
  nil
51
74
  end
@@ -20,8 +20,12 @@ module JustimmoClient::V1
20
20
 
21
21
  # @!group Instance Method Summary
22
22
 
23
- def country=(name)
24
- @country = Country.new(name: name)
23
+ def country=(code)
24
+ @country = Country.new(alpha3: code)
25
+ end
26
+
27
+ def country
28
+ @country&.alpha3
25
29
  end
26
30
 
27
31
  def floor=(flr)
@@ -6,6 +6,7 @@ module JustimmoClient::V1
6
6
  property :id
7
7
  property :alpha2
8
8
  property :alpha3
9
+ property :name
9
10
 
10
11
  collection_representer class: Country
11
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JustimmoClient
4
- VERSION = "0.6.5"
4
+ VERSION = "0.6.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justimmo_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Auernig