icecream 0.0.10 → 0.0.11
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 +4 -4
- data/README.md +12 -0
- data/lib/icecream/icecream.rb +4 -0
- data/lib/icecream/version.rb +1 -1
- data/spec/icecream_spec.rb +15 -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: 82e9776464a75175104c839f1639376b1ed9e62a
|
4
|
+
data.tar.gz: 2cc5414e69e87b049a53d088ed2c4c6eb2ff3d64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41a1c9e18c71c4a84ca6e5a4e2e297972f079bf018e83fce0138b1bbc61de6f1aeb8c0bc8e8f23142deaed41964f1c67ebc38445f20eb45405f063eaa969a66e
|
7
|
+
data.tar.gz: 8daba892d5280fe2fab8e3fca4f8623168dc37e0b2bbb6e019a57b00d3d3be1bc1caacd07b4f5def68970f7254fdd546c3760953f31e7b9451bb4d803dce1b13
|
data/README.md
CHANGED
@@ -60,6 +60,18 @@ You can also, define an object from nowhere, creating it with a single line!
|
|
60
60
|
|
61
61
|
$ IceCream::IceCream.flavor :Orange, "[name = 'orange', color = :orange, price = 35.5, calories = 3]"
|
62
62
|
|
63
|
+
If you are working with big sets of data, you can update information of an object with the information of another object using merge. For instance:
|
64
|
+
|
65
|
+
$ chocolate = @fridge.flavor :chocolate
|
66
|
+
# it has: name => "chocolate", color => :brown, price => 15.5 and calories => 150.
|
67
|
+
|
68
|
+
$ update = IceCream::IceCream.flavor :Update_chocolate, "[name = 'Dark Chocolate', price = 55.5]"
|
69
|
+
# you created a new object with part of the data that chocolate has
|
70
|
+
|
71
|
+
$ IceCream::IceCream.merge chocolate, update
|
72
|
+
$ chocolate
|
73
|
+
# returns: name => "Dark Chocolate", color => :brown, price => 55.5 and calories => 150.
|
74
|
+
|
63
75
|
Have fun!
|
64
76
|
|
65
77
|
Contributing
|
data/lib/icecream/icecream.rb
CHANGED
@@ -23,6 +23,10 @@ module IceCream
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.merge flavor, comp_flavor
|
27
|
+
flavor.instance_variables.each {|variable| flavor.send("#{variable.to_s[1,variable.to_s.size-1]}=".to_sym, comp_flavor.send(variable[1,variable.size-1].to_sym)) if comp_flavor.instance_variables.include? variable.to_sym }
|
28
|
+
end
|
29
|
+
|
26
30
|
def initialize(path)
|
27
31
|
Dir.glob("#{path}/*.flavor") do |flavor_file_path|
|
28
32
|
flavor = Parser.get_flavor flavor_file_path
|
data/lib/icecream/version.rb
CHANGED
data/spec/icecream_spec.rb
CHANGED
@@ -3,8 +3,10 @@ require File.dirname(__FILE__) + "/spec_helper"
|
|
3
3
|
|
4
4
|
describe "Icecream" do
|
5
5
|
describe "Gets all the objects to factory directory" do
|
6
|
-
|
6
|
+
before(:each) do
|
7
7
|
@fridge = IceCream::IceCream.new File.join(File.dirname(__FILE__),"flavors")
|
8
|
+
end
|
9
|
+
it "has objects for each file in the factory filder" do
|
8
10
|
|
9
11
|
chocolate = @fridge.flavor :chocolate
|
10
12
|
chocolate.class.should be Chocolate
|
@@ -36,5 +38,17 @@ describe "Icecream" do
|
|
36
38
|
new_flavor.price.should eq 35.5
|
37
39
|
new_flavor.calories.should eq 3
|
38
40
|
end
|
41
|
+
it "merges the objects" do
|
42
|
+
cream = @fridge.flavor :cream
|
43
|
+
complementary_flavor = IceCream::IceCream.flavor :Orange, "[name = 'orange', price = 35.5]"
|
44
|
+
|
45
|
+
IceCream::IceCream.merge cream, complementary_flavor
|
46
|
+
|
47
|
+
cream.class.should be Cream
|
48
|
+
cream.name.should eq "orange"
|
49
|
+
cream.color.should eq :yellow
|
50
|
+
cream.price.should eq 35.5
|
51
|
+
cream.calories.should eq 200
|
52
|
+
end
|
39
53
|
end
|
40
54
|
end
|