apple-news 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apple-news.rb +1 -0
- data/lib/apple-news/properties.rb +9 -5
- data/lib/apple-news/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c750e8520361db81736ea6f3ff81a95e339f45d
|
4
|
+
data.tar.gz: 1061eea5f9574edf0e08c1a078521d012002deca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c99a55c00daf17d10ce3af5257c8b8a20cc69b17b78b3af92785ca1771912114a7add9ad1f211950676332519ef56603efc1b9dc77e0744a6aa32b9fb08c1a4
|
7
|
+
data.tar.gz: dbee98d60a05b096c5ba997e8fd00bd8e2920a3b4fdc1fabb036c93811f107cba8325b1b7058969286470c06202e1230504654717e760c22a080b577d28d99b6
|
data/lib/apple-news.rb
CHANGED
@@ -2,6 +2,7 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
2
2
|
require "active_support/concern"
|
3
3
|
require "active_support/core_ext/class/attribute"
|
4
4
|
require "active_support/core_ext/string/inflections"
|
5
|
+
require "active_support/core_ext/object/blank"
|
5
6
|
|
6
7
|
require "base64"
|
7
8
|
require "json"
|
@@ -3,19 +3,23 @@ module AppleNews
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
def initialize(opts = nil)
|
6
|
-
load_properties(opts)
|
6
|
+
load_properties(opts)
|
7
7
|
end
|
8
8
|
|
9
9
|
def load_properties(opts)
|
10
|
-
opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
|
10
|
+
opts = ActiveSupport::HashWithIndifferentAccess.new(opts || {})
|
11
11
|
self.class.properties.each do |prop, settings|
|
12
12
|
val = if !settings[:klass].nil?
|
13
13
|
assigned_val = opts.fetch(prop, settings[:default])
|
14
14
|
|
15
15
|
if settings[:default].is_a?(Array)
|
16
|
-
assigned_val.map { |v|
|
16
|
+
assigned_val.map { |v|
|
17
|
+
v.is_a?(Hash) ? settings[:klass].send(settings[:init_method], v) : v
|
18
|
+
}
|
17
19
|
elsif settings[:default].is_a?(Hash)
|
18
|
-
Hash[assigned_val.map { |k, v|
|
20
|
+
Hash[assigned_val.map { |k, v|
|
21
|
+
[k, v.is_a?(Hash) ? settings[:klass].send(settings[:init_method], v) : v]
|
22
|
+
}]
|
19
23
|
elsif !assigned_val.nil? && !assigned_val.is_a?(Class)
|
20
24
|
assigned_val
|
21
25
|
else
|
@@ -65,7 +69,7 @@ module AppleNews
|
|
65
69
|
send(key)
|
66
70
|
end
|
67
71
|
|
68
|
-
[json_key, val]
|
72
|
+
[json_key, val.blank? ? nil : val]
|
69
73
|
}.reject { |p| p[1].nil? }]
|
70
74
|
end
|
71
75
|
end
|
data/lib/apple-news/version.rb
CHANGED