squares 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 074e6796ea7c42df0e23113ab954902efbdb6ec2
4
- data.tar.gz: 0fc9fc0ce29dffe3cf33a596125982f8eb5ffd90
3
+ metadata.gz: de5127c42ca404a5c0ba192a7cce5cb9efbeb929
4
+ data.tar.gz: e165de18d68aeb5ce113b13e02b172f8cea26b02
5
5
  SHA512:
6
- metadata.gz: 7b15a683f326faaa5cb5c44d325191f6f9434db48ab30f76a5bfba15434e15fc50e4190947dbd2f2a3a18704d432088db6139ae28413140122d66c2c3a9ff4cb
7
- data.tar.gz: 393d71e21ef1912e536bed9d72c69bf550fa3efea8e0c592079fcd718a51e693548a3fecbf62f64f3d17375ef466fd818df3b4fbd34efc5bafc56eaddc4ccf30
6
+ metadata.gz: a53b475c52095181a40454bf33584c45c797e584ae87b28478d0ab60714c7ad1573badc92e1b462e09964cb6435a7d7ba1ccb7ce929b4aecec822e314ab16e98
7
+ data.tar.gz: 3c5d2ca85ab287f30a56ecb01657ef30690697ec12342e21b98c1bd3ae9d769042040e9ccdf85e861f8c123b74876081841a56ddcff2a93df8e1930f25bee9a2
data/lib/squares/base.rb CHANGED
@@ -19,6 +19,14 @@ module Squares
19
19
  self.class.properties
20
20
  end
21
21
 
22
+ def to_h(key_name = :id)
23
+ h = { key_name => id }
24
+ properties.each do |property|
25
+ h[property] = self.send(property)
26
+ end
27
+ h
28
+ end
29
+
22
30
  private
23
31
 
24
32
  def properties_equal other
@@ -1,3 +1,3 @@
1
1
  module Squares
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.8"
3
3
  end
@@ -138,6 +138,21 @@ module Squares
138
138
  Then { frozen_hero.class == Marvel::SuperHero }
139
139
  end
140
140
 
141
+ describe '#to_h' do
142
+ Given(:hero1) { test_class.new id, real_name: name, special_powers: powers }
143
+ context 'default key name' do
144
+ Given(:expected_hash) { { id: id, real_name: name, special_powers: powers } }
145
+ When(:result) { hero1.to_h }
146
+ Then { expect(result).to eq(expected_hash) }
147
+ end
148
+
149
+ context 'custom key name' do
150
+ Given(:expected_hash) { { hero: id, real_name: name, special_powers: powers } }
151
+ When(:result) { hero1.to_h(:hero) }
152
+ Then { expect(result).to eq(expected_hash) }
153
+ end
154
+ end
155
+
141
156
  describe '#==' do
142
157
  Given(:hero1) { test_class.new id, real_name: name, special_powers: powers }
143
158
  Given(:hero2) { test_class.new id, real_name: name, special_powers: powers }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squares
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Helbling