cinch-convert 0.0.1 → 1.0.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.
- data/.travis.yml +6 -0
- data/README.md +6 -0
- data/Rakefile +6 -0
- data/cinch-convert.gemspec +7 -0
- data/lib/cinch/plugins/convert/convert.rb +19 -23
- data/lib/cinch/plugins/convert/version.rb +1 -1
- data/spec/cinch-convert_spec.rb +51 -0
- data/spec/spec_helper.rb +5 -0
- metadata +90 -4
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Cinch::Plugins::Convert
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/cinch-convert)
|
4
|
+
[](https://gemnasium.com/canonical-hackers/cinch-convert)
|
5
|
+
[](https://travis-ci.org/canonical-hackers/cinch-convert)
|
6
|
+
[](https://coveralls.io/r/canonical-hackers/cinch-convert?branch=master)
|
7
|
+
[](https://codeclimate.com/github/canonical-hackers/cinch-convert)
|
8
|
+
|
3
9
|
Cinch Plugin to allow users to convert units.
|
4
10
|
|
5
11
|
## Installation
|
data/Rakefile
CHANGED
data/cinch-convert.gemspec
CHANGED
@@ -16,4 +16,11 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'coveralls'
|
23
|
+
gem.add_development_dependency 'cinch-test'
|
24
|
+
|
25
|
+
gem.add_dependency 'cinch', '~> 2.0.5'
|
19
26
|
end
|
@@ -1,53 +1,49 @@
|
|
1
|
+
require 'cinch'
|
2
|
+
|
1
3
|
module Cinch::Plugins
|
2
4
|
class Convert
|
3
5
|
include Cinch::Plugin
|
4
6
|
|
5
7
|
self.help = "Use .convert <thing 1> to <thing 2> to do a unit conversion. (e.g. .convert 5 feet to meters)"
|
6
8
|
|
7
|
-
match /convert (.+)/
|
9
|
+
match /convert (.+) to (.+)/
|
8
10
|
|
9
11
|
def initialize(*args)
|
10
12
|
super
|
11
13
|
@units_path = config[:units_path] || '/usr/bin/units'
|
12
14
|
end
|
13
15
|
|
14
|
-
def execute(m,
|
15
|
-
m.reply convert(
|
16
|
+
def execute(m, from, to)
|
17
|
+
m.reply convert(from, to), true
|
16
18
|
end
|
17
19
|
|
18
20
|
private
|
19
21
|
|
20
|
-
def convert(
|
21
|
-
unless
|
22
|
-
debug "Cinch can't find the unit conversion binary."
|
23
|
-
return "Sorry I can't convert that."
|
24
|
-
end
|
25
|
-
|
26
|
-
match = conversion.match(/([+\d\.-]+)\s*([\/*\s\w]+) to ([\/*\s\w]+)$/)
|
22
|
+
def convert(from, to)
|
23
|
+
return "Sorry, there's a configuration issue." unless units_binary_exists?
|
27
24
|
|
28
|
-
unless
|
29
|
-
|
30
|
-
units_from = match[2]
|
31
|
-
units_to = match[3]
|
32
|
-
|
33
|
-
units_output = IO.popen([@units_path, "-t", "#{num} #{units_from}", units_to])
|
25
|
+
unless from.nil? || to.nil?
|
26
|
+
units_output = IO.popen([@units_path, "-t", from, to])
|
34
27
|
|
35
28
|
# we only take one line here because the first line of output is
|
36
29
|
# either an error message or the part of the conversion output we
|
37
30
|
# want.
|
38
|
-
units_line = units_output.readline
|
39
|
-
units_line.chomp!
|
31
|
+
units_line = units_output.readline.chomp!
|
40
32
|
|
41
|
-
if units_line
|
33
|
+
if units_line.match(/Unknown unit/)
|
42
34
|
"Sorry, #{units_line.downcase}."
|
43
|
-
elsif units_line
|
35
|
+
elsif units_line.match(/conformability error/)
|
44
36
|
"Sorry, there was a conformability error when making that conversion."
|
45
37
|
else
|
46
|
-
"#{
|
38
|
+
"#{from} is #{units_line} #{to}."
|
47
39
|
end
|
48
|
-
else
|
49
|
-
"Sorry, I don't understand, please use `.convert X unitname to unitname`."
|
50
40
|
end
|
51
41
|
end
|
42
|
+
|
43
|
+
def units_binary_exists?
|
44
|
+
return true if File.exist? @units_path
|
45
|
+
debug "Cinch can't find the unit conversion binary."
|
46
|
+
false
|
47
|
+
end
|
52
48
|
end
|
53
49
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cinch::Plugins::Convert do
|
4
|
+
|
5
|
+
include Cinch::Test
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@bot = make_bot(Cinch::Plugins::Convert)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'configuration' do
|
12
|
+
it 'should handle the units binary\'s absence with grace' do
|
13
|
+
@bot = make_bot(Cinch::Plugins::Convert, { :units_path => '/usr/baddir/units' })
|
14
|
+
msg = make_message(@bot, '!convert 3 foo to bar')
|
15
|
+
get_replies(msg).last.chomp.
|
16
|
+
should == 'test: Sorry, there\'s a configuration issue.'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'conversions' do
|
21
|
+
it 'should alow users to convert units' do
|
22
|
+
msg = make_message(@bot, '!convert 2 inches to feet')
|
23
|
+
get_replies(msg).last.chomp.
|
24
|
+
should == 'test: 2 inches is 0.16666667 feet.'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow users to convert temps' do
|
28
|
+
msg = make_message(@bot, '!convert tempF(32) to tempC')
|
29
|
+
get_replies(msg).last.chomp.
|
30
|
+
should == 'test: tempF(32) is 0 tempC.'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return an error on conformability issues' do
|
34
|
+
msg = make_message(@bot, '!convert 15 minutes to gallons')
|
35
|
+
get_replies(msg).last.chomp.
|
36
|
+
should == 'test: Sorry, there was a conformability error when making that conversion.'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return an error on invalid units' do
|
40
|
+
msg = make_message(@bot, '!convert 15 foo to bar')
|
41
|
+
get_replies(msg).last.chomp.
|
42
|
+
should == 'test: Sorry, unknown unit \'foo\'.'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'shouldn\'t return anything on invalid conversions' do
|
46
|
+
msg = make_message(@bot, '!convert foo 15 foo baz bar')
|
47
|
+
get_replies(msg).
|
48
|
+
should be_empty
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-convert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,8 +10,88 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
14
|
-
dependencies:
|
13
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rspec
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: coveralls
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: cinch-test
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: cinch
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.0.5
|
87
|
+
type: :runtime
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.0.5
|
15
95
|
description: Cinch Plugin for Coverting Units via the units binary
|
16
96
|
email:
|
17
97
|
- bhaberer@gmail.com
|
@@ -20,6 +100,7 @@ extensions: []
|
|
20
100
|
extra_rdoc_files: []
|
21
101
|
files:
|
22
102
|
- .gitignore
|
103
|
+
- .travis.yml
|
23
104
|
- Gemfile
|
24
105
|
- LICENSE.txt
|
25
106
|
- README.md
|
@@ -28,6 +109,8 @@ files:
|
|
28
109
|
- lib/cinch-convert.rb
|
29
110
|
- lib/cinch/plugins/convert/convert.rb
|
30
111
|
- lib/cinch/plugins/convert/version.rb
|
112
|
+
- spec/cinch-convert_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
31
114
|
homepage: https://github.com/canonical-hackers/cinch-convert
|
32
115
|
licenses: []
|
33
116
|
post_install_message:
|
@@ -52,4 +135,7 @@ rubygems_version: 1.8.24
|
|
52
135
|
signing_key:
|
53
136
|
specification_version: 3
|
54
137
|
summary: Cinch Plugin for converting units
|
55
|
-
test_files:
|
138
|
+
test_files:
|
139
|
+
- spec/cinch-convert_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
has_rdoc:
|