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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89ec0ccf7598a2ab1c8b56db94edd41673e3cc9b
4
- data.tar.gz: e1f700824645bd25cdc8c634cc4797f809220121
3
+ metadata.gz: 0c750e8520361db81736ea6f3ff81a95e339f45d
4
+ data.tar.gz: 1061eea5f9574edf0e08c1a078521d012002deca
5
5
  SHA512:
6
- metadata.gz: e34c083dd32ef1b2f9c0281c7833599c1b387c6bef83f4dd366732c621042e0ff8300b331571ba6919527b26448d8248407e39da5b91256ea606fb0495b279fb
7
- data.tar.gz: 06f0d6ef9f91c4a7c7766c662a6ba3d7bdb3162687ac80375aff791e16982d34d46f19f94826aa17397df1e195bc1efa40c2dd1aaab42d0747af48de17cb4577
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) if !opts.nil?
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| settings[:klass].send(settings[:init_method], 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| [k, settings[:klass].send(settings[:init_method], 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
@@ -1,3 +1,3 @@
1
1
  module AppleNews
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple-news
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan LeFevre