hello_ruby_calculator 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca1e53be205785ac872aecea7733a5a261bdf836
4
+ data.tar.gz: 1e23fafdf3dd3dd3b78610978a09dd95bb2b5de9
5
+ SHA512:
6
+ metadata.gz: 4593b5e454f566169d59168013e5735e63fa3890f3a369f82294cfb4c6fab03c1fe16cbd5981804f81e7bbe4c831477d3bb1199c09f363026a75b9f3b345766a
7
+ data.tar.gz: 9981f84c6562cd6d34882fb2f4c8beb2d339a5d8862eb53693c68d986c4797bf3460393e73b4fd253353cfe06d816c80df181b6c2d638ed524bb0f606553a56e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hello_ruby_calculator.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Felipe Pelizaro Gentil
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,18 @@
1
+ # HelloRubyCalculator
2
+
3
+ Simplest gem ever to introduce Ruby in the `Hello Ruby` course.
4
+ Slides can be found here: https://speakerdeck.com/fpgentil/hello-ruby
5
+
6
+ ## Installation
7
+
8
+ ```
9
+ $ gem install hello_ruby_calculator
10
+ ```
11
+
12
+ ## Contributing
13
+
14
+ 1. Fork it ( https://github.com/[my-github-username]/hello_ruby_calculator/fork )
15
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
16
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
17
+ 4. Push to the branch (`git push origin my-new-feature`)
18
+ 5. Create a new Pull Request
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Default task"
4
+ task default: :spec
5
+
6
+ desc "Open an irb session preloaded with this library"
7
+ task :console do
8
+ sh "irb -rubygems -I lib -r hello_ruby_calculator/calculator.rb"
9
+ end
10
+
11
+ desc "Run specs"
12
+ task :spec do
13
+ system "rspec ."
14
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hello_ruby_calculator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hello_ruby_calculator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hello_ruby_calculator"
8
+ spec.version = HelloRubyCalculator::VERSION
9
+ spec.authors = ["Felipe Pelizaro Gentil"]
10
+ spec.email = ["ruby@rails.com"]
11
+
12
+ spec.summary = %q{Simple Calculator to introduce Ruby in Hello Ruby course}
13
+ spec.description = %q{It simply performs the four basic math operations}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "simplecov", "~> 0.9.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0.0"
26
+ spec.add_development_dependency "pry-meta"
27
+ end
@@ -0,0 +1,6 @@
1
+ require "hello_ruby_calculator/version"
2
+ require "hello_ruby_calculator/calculator"
3
+
4
+ module HelloRubyCalculator
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,46 @@
1
+ module HelloRubyCalculator
2
+ class Calculator
3
+ attr_reader :args
4
+
5
+ def sum *args
6
+ @args = args
7
+ validate_params
8
+
9
+ args.reduce(:+)
10
+ end
11
+
12
+ def subtract *args
13
+ @args = args
14
+ validate_params
15
+
16
+ args.reduce(:-)
17
+ end
18
+
19
+ def multiply *args
20
+ @args = args
21
+ validate_params
22
+
23
+ args.reduce(:*)
24
+ end
25
+
26
+ def divide *args
27
+ @args = args
28
+ validate_params
29
+
30
+ args.reduce(:/)
31
+ end
32
+
33
+ private
34
+ def only_numbers?
35
+ @args.all?{ |arg| arg.is_a? Fixnum }
36
+ end
37
+
38
+ def validate_params
39
+ raise EmptyParams if @args.empty?
40
+ raise WrongParams unless only_numbers?
41
+ end
42
+ end
43
+
44
+ class EmptyParams < StandardError; end;
45
+ class WrongParams < StandardError; end;
46
+ end
@@ -0,0 +1,3 @@
1
+ module HelloRubyCalculator
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hello_ruby_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felipe Pelizaro Gentil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-meta
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: It simply performs the four basic math operations
84
+ email:
85
+ - ruby@rails.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - hello_ruby_calculator.gemspec
100
+ - lib/hello_ruby_calculator.rb
101
+ - lib/hello_ruby_calculator/calculator.rb
102
+ - lib/hello_ruby_calculator/version.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.6
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Simple Calculator to introduce Ruby in Hello Ruby course
127
+ test_files: []