Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pickhardt committed Sep 22, 2014
2 parents bffeef9 + 7c2d950 commit 3829fc7
Show file tree
Hide file tree
Showing 22 changed files with 482 additions and 196 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

group :development do
gem 'pry'
gem 'rspec'
end
30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.0)
diff-lcs (1.2.5)
method_source (0.8.2)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
slop (3.5.0)

PLATFORMS
ruby

DEPENDENCIES
pry
rspec
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Betty (version 0.1.6)
Betty (version 0.1.7)
=====================
![circle ci build](https://circleci.com/gh/pickhardt/betty/tree/dev.png)

Betty is a friendly English-like interface for your command line.

Expand Down Expand Up @@ -158,6 +159,10 @@ Contributing

Contributions are welcome! If you would like to contribute, please issue a pull request against the **dev branch**, not the master branch.

Please ensure that you use soft tabs, converting tabs to spaces. Do not use actual tab characters because it will make the spacing look weird in others' text editors.

Please make sure that the tests pass and try to write tests for your contributions. To check the tests, first run `bundle install` followed by `bundle exec rspec spec`


Versioning
----------
Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
10 changes: 10 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
0.1.7 (September 21, 2014)
--------------------------

Added rock, paper, scissors.

Added some tests.

Fixed a bug with the copy and move commands.


0.1.6 (May 26, 2014)
--------------------

Expand Down
6 changes: 6 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
pre:
- bundle install
test:
override:
- bundle exec rspec spec
97 changes: 93 additions & 4 deletions lib/calc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,97 @@ def numeric?
module Calculate
def self.interpret(command)
responses = []


matches = command.match(/^what\s+is\s+(?:the\s+)?(?:square\s+root|sqrt)\s+of\s+(.+)$/)
if matches

if matches[1].numeric?
arg1 = matches[1]
else
return []
end

responses << {
command: "echo 'scale=10;sqrt(#{arg1})' | bc",
explanation: "Calculates square root of #{arg1}"
}
return responses
end


matches = command.match(/^what\s+is\s+(?:the\s+)?(square|cube)\s+of\s+(.+)$/)
if matches

power_text = matches[1]
if power_text == 'square'
power = 2
elsif power_text == 'cube'
power = 3
else
return []
end

if matches[2].numeric?
arg1 = matches[2]
else
return []
end

responses << {
command: "echo '#{arg1}^#{power}' | bc",
explanation: "Calculates #{power_text} of #{arg1}"
}
return responses
end


matches = command.match(/^what\s+is\s+(.+)\s+(to\s+the|to\s+the\s+power\s+of|power)\s+(.+)$/)
if matches

if ( matches[1].gsub(/(\s+|to|the|of)/,"").numeric? && matches[3].gsub(/(\s+|to|the|of)/,"").numeric?)
arg1 = matches[1].gsub(/(\s+|to|the|of)/,"")
arg3 = matches[3].gsub(/(\s+|to|the|of)/,"")
else
return []
end

responses << {
command: "echo '#{arg1}^#{arg3}' | bc",
explanation: "Calculates #{arg1} to the power of #{arg3}"
}
return responses
end


matches = command.match(/^what\s+is\s+(?:the\s+)?(.+)\s?(?:%|percent)\s+of\s+(.+)$/)
if matches

if ( matches[1].numeric? && matches[2].numeric? )
arg1 = matches[1].strip
arg2 = matches[2].strip
else
return []
end

responses << {
command: "echo 'scale=2;#{arg1}*#{arg2}/100' | bc",
explanation: "Calculates #{arg1} percent of #{arg2}"
}
return responses
end


matches = command.match(/^what\s+is\s+(.+)\s+(.+)\s(.+)$/)

if matches

if (matches[1].numeric? && matches[3].numeric?)
arg1 = matches[1]
arg2 = matches[3]
else
return []
end

oper = matches[2]
if ["plus", "+"].include?(oper)
op = "+"
Expand All @@ -26,15 +107,18 @@ def self.interpret(command)
op = "*"
elsif ["by", "divided", "divied by", "/"].include?(oper)
op = "/"
elsif ["mod", "module", "%"].include?(oper)
op = "%"
else
return []
end

responses << {
command: "bc <<< #{arg1}#{op}#{arg2}",
command: "echo '#{arg1}#{op}#{arg2}' | bc",
explanation: "Calculates #{arg1}#{op}#{arg2}"
}
end

responses
end

Expand All @@ -43,7 +127,12 @@ def self.help
commands << {
category: "Calculate",
description: '\033[34mCalculate\033[0m',
usage: ["- betty what is 40 plus 2"]
usage: ["what is 40 plus 2",
"what is the square root of 9",
"what is the cube of 3",
"what is 3 to the power of 4",
"what is the 11 percent of 200",
"what is 26 mod 5"]
}
commands
end
Expand Down
Loading

0 comments on commit 3829fc7

Please sign in to comment.