icecream 0.0.4 → 0.0.5

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: 98daa3902e28f8dee3841790c3920324e5bcf408
4
- data.tar.gz: c4c73c808e335146b08cadc93f0eddecb0366a1d
3
+ metadata.gz: 19a4e8aa6b77f069fcfb01613769ca49d2851e66
4
+ data.tar.gz: 30b0b2f8310aaed9c3039ddbd843e584fc1d2ca9
5
5
  SHA512:
6
- metadata.gz: e7b60a6ded8c6062881375de7c74ca3cab07eee25d7825b6a0fcb053c30696a09974e0a9b33de886143fe6a57f8fa6d6f3062b8e92d5f7a7ccabce72c3f8e969
7
- data.tar.gz: dbb74a585c3d28783810195928f550f098d29450fe3a2bdfbac32afc191fe0ac51ee0f78b2decefdce6646718135a7e12326571d7773df12878ea0f548fc7ba2
6
+ metadata.gz: d564553924e7515c4d9762a17f4575ec923b9c5af03c72cad588028681527c29eae86fb006ffe2bc842ee7c5c813e80f3fc6bb5584981f5e0c1b66de74706c42
7
+ data.tar.gz: 4b7cd5d03cd00d14a9e4659471d8e78c2aa1703868e8c3eca852bc4b1b9f67d37c254981fcdbb256a6136ac08dd93f3aca6ff97b255a2691198f3541d70c117f
data/README.md CHANGED
@@ -5,15 +5,15 @@ IceCream
5
5
 
6
6
  !!!WORK IN PROGRESS!!!
7
7
 
8
- I was looking for a really simple factory gem, such as factory_grill, but without any magic to use with rails. I was imcompetent at that, so I built this really simple Factory called IceCream.
8
+ I was looking for a really simple factory gem, such as factory_grill, but without any magic to use with rails. I was incompetent at that, so I built this really simple Factory called IceCream.
9
9
 
10
10
  It is a IceCream factory. It means that you can fabricate any IceCream flavor that you have in your fridge :D And, as any Factory, you can change the properties of an object that you got from the fridge.
11
11
 
12
12
  The idea
13
13
  -------
14
- The central idea is to have a very simple file to describe what you want to fabricate. When I say simple, I mean SIMPLE. The file is just a file with two collums: variable and default value.
14
+ The central idea is to have a very simple file to describe what you want to fabricate. When I say simple, I mean SIMPLE. The file is just a "file.flavor" (plain text) with two collums: variable and default value.
15
15
 
16
- This gem goes to the factory directory and for each file, it is going to create a class (with the file name) and fill this class with instance variables for each one of the variables, and, of course set the value for the variables :)
16
+ This gem goes to the factory directory and for each ".flavor" file, it is going to create a class (with the file name) and fill this class with instance variables for each one of the variables, and, of course set the value for the variables :)
17
17
 
18
18
  Imagine a file called chocolate.flavor that has the following content
19
19
 
@@ -26,14 +26,41 @@ At the end, you can call the IceCream factory using the following commands:
26
26
 
27
27
  $ IceCream.flavor :chocolate
28
28
 
29
- and it is going to return a Chocolate (class) object called chocolate, with a string, a symble, a float and an integer. Easy ;)
29
+ and it is going to return a Chocolate (class) object called chocolate, with a string, a symbol, a float and an integer. Easy ;)
30
30
 
31
31
  And it is going to work in your non-rails as good as in your rails projects :D It is just ruby code, there is not one single dependency (so far).
32
32
 
33
+ Installing
34
+ ------------------
33
35
 
36
+ Terminal
37
+
38
+ $ gem install icecream
39
+
40
+ Gemfile
41
+
42
+ $ gem 'icecream'
43
+
44
+ Using
45
+ ---------
46
+
47
+ $ require 'icecream'
48
+ $ creamy_flavors = IceCream::Icecream.new "/path/to/flavors"
49
+ $ cheap_chocolate = creamy_flavors.flavor :chocolate
50
+ $ cheap_chocolate.name= "whathever you want :)"
51
+ # You can have as many "factories" as you need
52
+ $ diet_flavors = IceCream::Icecream.new "/path/to/Diet/flavors"
53
+ $ zero_sugar_chocolate = diet_flavors.flavor :chocolate
54
+
55
+ Have fun!
56
+
57
+ Contributing
58
+ --------------
59
+
60
+ Fork, pull request, thank you :)
34
61
 
35
62
  LICENCE
36
- =======
63
+ -------------
37
64
 
38
65
  Copyright 2013 Camilo Ribeiro camilo@camiloribeiro.com
39
66
 
@@ -12,6 +12,7 @@ module IceCream
12
12
  "@"+instance_name
13
13
  end
14
14
  define_singleton_method(instance_name+"=") do |new_value|
15
+ require "pry"; binding.pry
15
16
  "@"+instance_name = new_value
16
17
  end
17
18
  end
@@ -27,7 +27,6 @@ module IceCream
27
27
  end
28
28
 
29
29
  def self.fix_value value
30
- #require "pry"; binding.pry
31
30
  if value[0] == ":"
32
31
  final = value.gsub(":","").to_sym
33
32
  elsif !value.slice("\"").nil?
@@ -42,26 +41,24 @@ module IceCream
42
41
  final
43
42
 
44
43
  end
45
-
46
-
47
44
  def self.objectify flavor, all_particularities
48
45
  class_name = flavor.capitalize
49
46
  klass = Object.const_set(class_name,Class.new)
50
47
  variables = all_particularities.each { | particularity | parse_variables particularity }
51
48
  values = all_particularities.each { | particularity | parse_values particularity }
52
-
49
+
50
+
51
+
53
52
  klass.class_eval do
54
53
  attr_accessor *variables
55
54
 
56
55
  define_method(:initialize) do
57
56
  variables.each_with_index do |variable_name,i|
58
- instance_variable_set("@"+variable_name, values[i])
57
+ instance_variable_set("@"+variable_name, Parser.fix_value(values[i]))
59
58
  end
60
59
  end
61
60
  end
62
61
  obj = klass.new
63
62
  end
64
-
65
-
66
63
  end
67
64
  end
@@ -1,3 +1,3 @@
1
1
  module IceCream
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -7,12 +7,24 @@ describe "Icecream" do
7
7
 
8
8
  chocolate = @fridge.flavor :chocolate
9
9
  chocolate.class.should be Chocolate
10
+ chocolate.name.should eq "chocolate"
11
+ chocolate.color.should eq :brown
12
+ chocolate.price.should eq 15.5
13
+ chocolate.calories.should eq 150
10
14
 
11
15
  cream = @fridge.flavor :cream
12
16
  cream.class.should be Cream
17
+ cream.name.should eq "cream"
18
+ cream.color.should eq :yellow
19
+ cream.price.should eq 17.5
20
+ cream.calories.should eq 200
13
21
 
14
22
  apple = @fridge.flavor :apple
15
23
  apple.class.should be Apple
24
+ apple.name.should eq "apple"
25
+ apple.color.should eq :red
26
+ apple.price.should eq 1.5
27
+ apple.calories.should eq 1500
16
28
  end
17
29
  end
18
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icecream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Ribeiro