recipe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in recipe.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Cyberarm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Recipe
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'recipe'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install recipe
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/recipe/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,10 @@
1
+ require "stringio"
2
+
3
+ require "recipe/version"
4
+ require "recipe/dsl/dsl"
5
+ require "recipe/mix/mix"
6
+ require "recipe/ingredients/ingredient"
7
+ require "recipe/instructions/instruction"
8
+
9
+ require "recipe/printer/printer"
10
+ require "recipe/printer/rubyist_printer"
@@ -0,0 +1,40 @@
1
+ module Recipe
2
+ class DSL
3
+ attr_accessor :name, :elements, :mixes
4
+ def initialize(&block)
5
+ @name = "Recipe"
6
+ @elements = []
7
+ @mixes = []
8
+ yield(self)
9
+ end
10
+
11
+ def name(string = 'Recipe')
12
+ @name = string
13
+ end
14
+
15
+ def mix(name)
16
+ @elements << Recipe::Mix.new(name)
17
+ @mixes << []
18
+ end
19
+
20
+ def ingredient(name, measurement)
21
+ if @mixes.count > 0
22
+ @mixes[@mixes.count-1] << Recipe::Ingredient.new(name, measurement)
23
+ else
24
+ @elements << Recipe::Ingredient.new(name, measurement)
25
+ end
26
+ end
27
+
28
+ def instruction(text)
29
+ if @mixes.count > 0
30
+ @mixes[@mixes.count-1] << Recipe::Instruction.new(text)
31
+ else
32
+ @elements << Recipe::Instruction.new(text)
33
+ end
34
+ end
35
+
36
+ def printer(klass)
37
+ klass.new(name, elements, mixes)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ module Recipe
2
+ class Ingredient
3
+ attr_reader :name, :measurement
4
+ def initialize(name, measurement)
5
+ @name = name
6
+ @measurement = measurement
7
+ end
8
+
9
+ # The name of the the ingredient, e.g. 'Wheat flour'
10
+ def name=(string)
11
+ @name = string
12
+ end
13
+
14
+ # Amount to add to mixture. e.g. '3 cups'
15
+ def measurement=(string)
16
+ @amount = string
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Recipe
2
+ class Instruction
3
+ attr_reader :text
4
+ def initialize(text)
5
+ @text = text
6
+ end
7
+
8
+ # The text of an instruction. e.g. "heat over to 350F"
9
+ def text=(string)
10
+ @text = text
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Recipe
2
+ class Mix
3
+ attr_reader :name
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ def name=(name)
9
+ @name = name
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module Recipe
2
+ class Printer
3
+ def initialize
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,92 @@
1
+ module Recipe
2
+ class RubyistPrinter < Recipe::Printer
3
+ def initialize(name, elements, mixes = nil)
4
+ @name = name
5
+ @elements = elements
6
+ @mixes = mixes
7
+ @string_io = StringIO.new
8
+ push_out
9
+ end
10
+
11
+ def ingredient(element)
12
+ @string_io << "def #{element.name.downcase.gsub(" ", '_')}\n"
13
+ @string_io << "'#{element.measurement}'\n"
14
+ @string_io << "end\n"
15
+ end
16
+
17
+ def instruction(element)
18
+ @string_io << "def instruction_#{@instruction_counter}\n"
19
+ @string_io << "'#{element.text}'\n"
20
+ @string_io << "end\n"
21
+ @instruction_counter+=1
22
+ end
23
+
24
+ def push_out
25
+ @string_io << "class #{@name.capitalize.gsub(" ", '')}\n"
26
+ @instruction_counter = 0
27
+
28
+ if @mixes.is_a?(Array) && @mixes.count >= 1
29
+ mix_id = 0
30
+ @mixes.each do |mix|
31
+ counter = 0
32
+ @string_io << "class #{@elements[mix_id].name.split(' ').each{ |i| i.capitalize}.join('').gsub(" ", '')}\n"
33
+ mix.each do |object|
34
+ case object.class.to_s
35
+ when "Recipe::Instruction"
36
+ instruction(object)
37
+ when "Recipe::Ingredient"
38
+ ingredient(object)
39
+ end
40
+ @string_io << "\n" unless counter >= mix.count
41
+ end
42
+ @string_io << "end\n"
43
+ @string_io << "\n" unless counter >= mix.count
44
+ mix_id+=1
45
+ end
46
+ @string_io << "end\n"
47
+
48
+ else
49
+ counter = 0
50
+ @elements.each do |element|
51
+ case element.class.to_s
52
+ when "Recipe::Instruction"
53
+ instruction(element)
54
+ when "Recipe::Ingredient"
55
+ ingredient(element)
56
+ end
57
+ @string_io << "\n" unless counter >= @elements.count-1
58
+ counter+=1
59
+ end
60
+ @string_io << "end\n"
61
+ end
62
+
63
+ format_string
64
+ end
65
+
66
+ def format_string
67
+ indent = 0
68
+ spaces = ""
69
+ prev_line = nil
70
+
71
+ @string_io.string.each_line do |line|
72
+ line = line.strip
73
+ if prev_line
74
+ indent+=2 if prev_line.start_with?("class ") or prev_line.start_with?("def ")
75
+ indent-= 2 if line == 'end'
76
+
77
+ string = ""
78
+ indent.times do
79
+ string << " "
80
+ end
81
+ spaces = string
82
+ puts "#{spaces}#{line}"
83
+ else
84
+ puts line
85
+ end
86
+ prev_line = line
87
+ end
88
+
89
+ @string_io.close
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Recipe
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'recipe/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "recipe"
8
+ spec.version = Recipe::VERSION
9
+ spec.authors = ["Cyberarm"]
10
+ spec.email = ["matthewlikesrobots@gmail.com"]
11
+ spec.summary = %q{A DSL for describing a recipe.}
12
+ spec.description = %q{A DSL for describing a recipe.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cyberarm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ description: A DSL for describing a recipe.
47
+ email:
48
+ - matthewlikesrobots@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/recipe.rb
59
+ - lib/recipe/dsl/dsl.rb
60
+ - lib/recipe/ingredients/ingredient.rb
61
+ - lib/recipe/instructions/instruction.rb
62
+ - lib/recipe/mix/mix.rb
63
+ - lib/recipe/printer/printer.rb
64
+ - lib/recipe/printer/rubyist_printer.rb
65
+ - lib/recipe/version.rb
66
+ - recipe.gemspec
67
+ homepage: ''
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.29
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A DSL for describing a recipe.
92
+ test_files: []