data_container 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/data_container.rb +43 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03c86dfbb52a0999baa5294ecc389e03093c9b29
4
+ data.tar.gz: 65bce46c1b4a9d3fc0726dc36c7bcf4900fea413
5
+ SHA512:
6
+ metadata.gz: f5c14ecb983b260d46c959d33735c8ade3ff2beb5e2a4b2bff98ee9433387a5d8692175febfc98cb519c5182045d655ebb5af2f5edfc33f521b9ff47d369241c
7
+ data.tar.gz: dfc41ed0bca4730cff932ad27ec8fe0889a15a15a5a2ff0bbfecb8d66776b18f3f702af1084d06bb2ba115f8706d6cd05da7568af69b34f4ad3737b1f7389a81
@@ -0,0 +1,43 @@
1
+ class DataContainer < Struct
2
+ def self.new(*args)
3
+ super.new # send back an INSTANCE, not a class
4
+ end
5
+
6
+ def get(ivar)
7
+ send(ivar) if include?(ivar)
8
+ end
9
+
10
+ def set(ivar, value)
11
+ send("#{ivar}=", value) if include?(ivar)
12
+ end
13
+
14
+ def to_s
15
+ '@' + variable_value_pairs_string.join(', @')
16
+ end
17
+
18
+ def inspect
19
+ '#<DataContainer: ' + variable_value_pairs_string.join(' ') + '>'
20
+ end
21
+
22
+ def merge!(other_data_container)
23
+ other_data_container.each_pair do |var, val|
24
+ set(var, val) unless val.nil?
25
+ end
26
+ end
27
+
28
+ def include?(var)
29
+ data.include?(var.to_sym)
30
+ end
31
+
32
+ def populate_from_hash(hash)
33
+ hash.each { |var, val| set(var, val) }
34
+ end
35
+
36
+ alias_method :data, :members
37
+
38
+ private
39
+
40
+ def variable_value_pairs_string
41
+ each_pair.map { |ivar, value| "#{ivar}=#{value.inspect}" }
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_container
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kelli Searfos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: DataContainers store global/configuration values used throughout a project,
14
+ but not belonging to any individual object
15
+ email:
16
+ - ksearfos@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/data_container.rb
22
+ homepage: https://github.com/ksearfos/data_container
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: DataContainer class
45
+ test_files: []