pipl-api 2.0.2 → 3.0.0

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: 078c1c79c5fc8cebfd01d3aadafefc50faae5695
4
- data.tar.gz: 2c89534a0b4455a89896f89b71d535b0758d25c1
3
+ metadata.gz: ee84b5c43a1fa477a8fb25be47bd90c3e767b539
4
+ data.tar.gz: 0840470db0a882c3a659cc05ba11152bacc97141
5
5
  SHA512:
6
- metadata.gz: a3e2dbefe8c7c17e428b78ade8ecd234e536c53d65a2e6455f84435fdf763991d268571439a8f1572ac70344463283f957e7b47809df9b6e300ec2f527354fe2
7
- data.tar.gz: cf85a579a7f75d7f9439ee74957a7157d5a9a03cc221d2feefe0548b030ac04dcd722609e06835d87a1bcc3f74f2272ec3e21805fe50d6da2f0edd2b284bded8
6
+ metadata.gz: 51d274bbb869500305b5c234c3e9512afbcc9b321663210b7061c36043d1a4281dba2d0302660d7521ce09f8cd2fe39e4d7fdc090114ea1f08877f1d574708fe
7
+ data.tar.gz: a1e11a833c87ee7f0ffd1c64a219e50285f6616ed5966fb311c1a8f74fb25344494f8ad0dd60476ba6567ead259dbf7723954d44cafaac95b0007a6e25418bca
@@ -14,37 +14,45 @@ module Pipl
14
14
 
15
15
  def initialize(data)
16
16
  @name = Name.new(data["name"])
17
- @full_names = Name.new(data["full_names"]) unless data["full_names"] == {}
18
- @nicknames = Name.new(data["nicknames"]) unless data["nicknames"] == {}
19
- @spellings = Name.new(data["spellings"]) unless data["spellings"] == {}
20
- @translations = data["translations"] unless data["translations"] == {}
17
+ @full_names = convert_names(data["full_names"])
18
+ @nicknames = convert_names(data["nicknames"])
19
+ @spellings = convert_names(data["spellings"])
20
+ @translations = convert_names(data["translations"])
21
21
  @gender = Gender.new(data["gender"])
22
- @locations = data["top_locations"].map { |location| Location.new(location) }
23
- @ages = data["top_ages"].map { |age| Age.new(age) }
22
+ @locations = convert_locations(data["top_locations"])
23
+ @ages = convert_locations(data["top_ages"])
24
24
  @estimated_world_persons_count = data["estimated_world_persons_count"]
25
25
  end
26
26
 
27
27
  def to_hash
28
- [
29
- :name, :full_names, :nicknames,
30
- :spellings, :translations, :gender,
31
- :locations, :ages, :estimated_world_persons_count
32
- ].map do |accessor|
33
- value = case send(accessor)
34
- when Array then send(accessor).map(&:to_hash) if send(accessor).any?
35
- when Integer then send(accessor) if send(accessor)
36
- else send(accessor).to_hash if send(accessor)
37
- end
38
- { accessor => value }
39
- end.inject(&:merge!)
28
+ {
29
+ name: name.to_hash,
30
+ full_names: full_names.map(&:to_hash),
31
+ nicknames: nicknames.map(&:to_hash),
32
+ spellings: spellings.map(&:to_hash),
33
+ translations: translations.map(&:to_hash),
34
+ gender: gender.to_hash,
35
+ locations: locations.map(&:to_hash),
36
+ ages: ages.map(&:to_hash),
37
+ estimated_world_persons_count: estimated_world_persons_count
38
+ }
40
39
  end
41
40
  alias_method :to_h, :to_hash
42
41
 
43
-
44
42
  private
45
43
 
46
- def nil_or_hash(subject)
47
- subject.to_hash if subject
44
+ def convert_names(list)
45
+ list.map do |part, names|
46
+ names.map { |name| Name.new(part => name) }
47
+ end.flatten
48
+ end
49
+
50
+ def convert_locations(list)
51
+ list.map { |location| Location.new(location) }
52
+ end
53
+
54
+ def convert_ages(list)
55
+ list.map { |age| Age.new(age) }
48
56
  end
49
57
  end
50
58
  end
@@ -1,5 +1,5 @@
1
1
  module Pipl
2
2
  module API
3
- VERSION = "2.0.2"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pipl-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene