virtus_convert 0.0.1 → 0.1.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: 5c5c381b93ea5fe77c01bd3a067ff5e681ddbdc1
4
- data.tar.gz: acc0e6f24a7f73a006f312621321887f20cd8c3a
3
+ metadata.gz: 1d169c58fab7f68eae28103ae48b7fb05eda7b03
4
+ data.tar.gz: 48712121c22430ffedc5cfcde4410b2b997b30a1
5
5
  SHA512:
6
- metadata.gz: 25054f9067fa85c24abbd263d06f36f856dc45d18d14f05d169e92176c99a8bbaab7ce576f8f8c43fa4b424523659f754e354dcb5f24c29e4e79f11f270fff54
7
- data.tar.gz: 1396620431464bba748bda26d8932a2680a342c345d2b69eaf284b73867156aa31f6e1463b4eec03535cdf7132c70bfa88ff693593d3190b0b98aec49ae4e8c2
6
+ metadata.gz: bc1bca115e7b6f41ff027ab4a5302d22604952d189099ea4b719ace54f5fe1fcd666654d4b53714dedb4734830db26225962ea646e9da6ade25109ae479c99a7
7
+ data.tar.gz: aad4c766318ea22dd8dae7accdf570ae0163d7f29fc61de4b05b13db794b8e08f84b8a474896506e27900f8f06a9457e345521ccb156e41d1f7267cce77d2816
@@ -2,7 +2,7 @@ require "virtus_convert/version"
2
2
  require 'virtus_convert/converter'
3
3
 
4
4
  module VirtusConvert
5
- def self.new(unknown)
6
- VirtusConvert::Converter.new(unknown)
5
+ def self.new(unknown, options={})
6
+ VirtusConvert::Converter.new(unknown, options)
7
7
  end
8
8
  end
@@ -1,7 +1,8 @@
1
1
  module VirtusConvert
2
2
  class Array
3
- def initialize(array = [])
4
- @array = array.map{|item| VirtusConvert.new(item)}
3
+ def initialize(array = [], options = {})
4
+ array.reject!{|item| item.nil?} if options[:reject_nils]
5
+ @array = array.map{|item| VirtusConvert.new(item, options)}
5
6
  end
6
7
 
7
8
  def to_hash
@@ -6,10 +6,10 @@ module VirtusConvert
6
6
 
7
7
  class Converter
8
8
 
9
- def initialize(unknown)
10
- @root = VirtusConvert::Hash.new(unknown) if unknown.is_a? ::Hash
11
- @root ||= VirtusConvert::Array.new(unknown) if unknown.is_a? ::Array
12
- @root ||= VirtusConvert::Object.new(unknown)
9
+ def initialize(unknown, options = {})
10
+ @root = VirtusConvert::Hash.new(unknown, options) if unknown.is_a? ::Hash
11
+ @root ||= VirtusConvert::Array.new(unknown, options) if unknown.is_a? ::Array
12
+ @root ||= VirtusConvert::Object.new(unknown, options)
13
13
  end
14
14
 
15
15
  def to_hash
@@ -1,7 +1,8 @@
1
1
  module VirtusConvert
2
2
  class Hash
3
- def initialize(hash = {})
4
- @hash = hash.inject({}){|h,(k,v)| h[k] = VirtusConvert.new(v); h}
3
+ def initialize(hash = {}, options = {})
4
+ hash.reject!{|k, v| v.nil?} if options[:reject_nils]
5
+ @hash = hash.inject({}){|h,(k,v)| h[k] = VirtusConvert.new(v, options); h}
5
6
  end
6
7
 
7
8
  def to_hash
@@ -1,8 +1,8 @@
1
1
  module VirtusConvert
2
2
  class Object
3
- def initialize(object)
3
+ def initialize(object, options = {})
4
4
  if object.respond_to?(:attributes)
5
- @object = VirtusConvert.new(object.attributes)
5
+ @object = VirtusConvert.new(object.attributes, options)
6
6
  else
7
7
  @object = object
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module VirtusConvert
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtus_convert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Guest
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler