cinch-convert 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,7 +39,7 @@ alternate location.
39
39
 
40
40
  c.plugins.options[Cinch::Plugins::Convert][:units_path] = '/usr/bin/gunits'
41
41
 
42
- Once that's all done, just use `.convert x unit1 to unit2` in the channel.
42
+ Once that's all done, just use `!convert x unit1 to unit2` in the channel.
43
43
 
44
44
  ## Contributing
45
45
 
@@ -4,18 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/plugins/convert/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-convert"
7
+ gem.name = 'cinch-convert'
8
8
  gem.version = Cinch::Plugins::Convert::VERSION
9
- gem.authors = ["Brian Haberer", "Paul Visscher"]
10
- gem.email = ["bhaberer@gmail.com"]
9
+ gem.authors = ['Brian Haberer', 'Paul Visscher']
10
+ gem.email = ['bhaberer@gmail.com']
11
11
  gem.description = %q{Cinch Plugin for Coverting Units via the units binary}
12
12
  gem.summary = %q{Cinch Plugin for converting units}
13
- gem.homepage = "https://github.com/canonical-hackers/cinch-convert"
13
+ gem.homepage = 'https://github.com/canonical-hackers/cinch-convert'
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
+ gem.require_paths = ['lib']
19
20
 
20
21
  gem.add_development_dependency 'rake'
21
22
  gem.add_development_dependency 'rspec'
@@ -1,2 +1,3 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'cinch/plugins/convert/version'
2
- require 'cinch/plugins/convert/convert'
3
+ require 'cinch/plugins/convert'
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'cinch'
3
+
4
+ module Cinch::Plugins
5
+ # Cinch Plugin to convert units
6
+ class Convert
7
+ include Cinch::Plugin
8
+
9
+ self.help = 'Use .convert <thing 1> to <thing 2> to do a unit ' +
10
+ 'conversion. (e.g. .convert 5 feet to meters)'
11
+
12
+ match /convert (.+) to (.+)/
13
+
14
+ def initialize(*args)
15
+ super
16
+ @units_path = config[:units_path] || '/usr/bin/units'
17
+ end
18
+
19
+ def execute(m, from, to)
20
+ m.reply convert(from, to), true
21
+ end
22
+
23
+ private
24
+
25
+ def convert(from, to)
26
+ return "Sorry, there's a configuration issue." unless units_bin_exists?
27
+ return if from.nil? || to.nil?
28
+
29
+ units_line = get_units_output(from, to)
30
+
31
+ if units_line.match(/Unknown unit/)
32
+ "Sorry, #{units_line.downcase}."
33
+ elsif units_line.match(/conformability error/)
34
+ 'Sorry, there was an error when making that conversion.'
35
+ else
36
+ "#{from} is #{units_line} #{to}."
37
+ end
38
+ end
39
+
40
+ def get_units_output(from, to)
41
+ units_output = IO.popen([@units_path, '-t', from, to])
42
+
43
+ # we only take one line here because the first line of output is
44
+ # either an error message or the part of the conversion output we
45
+ # want.
46
+ units_output.readline.chomp!
47
+ end
48
+
49
+ def units_bin_exists?
50
+ return true if File.exist? @units_path
51
+ debug 'Cinch can not find the unit conversion binary.'
52
+ false
53
+ end
54
+ end
55
+ end
@@ -1,7 +1,9 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Cinch
2
3
  module Plugins
4
+ # Versioning information
3
5
  class Convert
4
- VERSION = "1.0.0"
6
+ VERSION = '1.0.1'
5
7
  end
6
8
  end
7
9
  end
@@ -12,7 +12,7 @@ describe Cinch::Plugins::Convert do
12
12
  it 'should handle the units binary\'s absence with grace' do
13
13
  @bot = make_bot(Cinch::Plugins::Convert, { :units_path => '/usr/baddir/units' })
14
14
  msg = make_message(@bot, '!convert 3 foo to bar')
15
- get_replies(msg).last.chomp.
15
+ get_replies(msg).last.text.
16
16
  should == 'test: Sorry, there\'s a configuration issue.'
17
17
  end
18
18
  end
@@ -20,25 +20,25 @@ describe Cinch::Plugins::Convert do
20
20
  describe 'conversions' do
21
21
  it 'should alow users to convert units' do
22
22
  msg = make_message(@bot, '!convert 2 inches to feet')
23
- get_replies(msg).last.chomp.
23
+ get_replies(msg).last.text.
24
24
  should == 'test: 2 inches is 0.16666667 feet.'
25
25
  end
26
26
 
27
27
  it 'should allow users to convert temps' do
28
28
  msg = make_message(@bot, '!convert tempF(32) to tempC')
29
- get_replies(msg).last.chomp.
29
+ get_replies(msg).last.text.
30
30
  should == 'test: tempF(32) is 0 tempC.'
31
31
  end
32
32
 
33
33
  it 'should return an error on conformability issues' do
34
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.'
35
+ get_replies(msg).last.text.
36
+ should == 'test: Sorry, there was an error when making that conversion.'
37
37
  end
38
38
 
39
39
  it 'should return an error on invalid units' do
40
40
  msg = make_message(@bot, '!convert 15 foo to bar')
41
- get_replies(msg).last.chomp.
41
+ get_replies(msg).last.text.
42
42
  should == 'test: Sorry, unknown unit \'foo\'.'
43
43
  end
44
44
 
@@ -1,5 +1,12 @@
1
1
  require 'coveralls'
2
- Coveralls.wear!
2
+ require 'simplecov'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
3
10
  require 'cinch-convert'
4
11
  require 'cinch/test'
5
12
 
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: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-01 00:00:00.000000000 Z
13
+ date: 2014-02-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -107,12 +107,13 @@ files:
107
107
  - Rakefile
108
108
  - cinch-convert.gemspec
109
109
  - lib/cinch-convert.rb
110
- - lib/cinch/plugins/convert/convert.rb
110
+ - lib/cinch/plugins/convert.rb
111
111
  - lib/cinch/plugins/convert/version.rb
112
112
  - spec/cinch-convert_spec.rb
113
113
  - spec/spec_helper.rb
114
114
  homepage: https://github.com/canonical-hackers/cinch-convert
115
- licenses: []
115
+ licenses:
116
+ - MIT
116
117
  post_install_message:
117
118
  rdoc_options: []
118
119
  require_paths:
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  requirements: []
133
134
  rubyforge_project:
134
- rubygems_version: 1.8.24
135
+ rubygems_version: 1.8.25
135
136
  signing_key:
136
137
  specification_version: 3
137
138
  summary: Cinch Plugin for converting units
@@ -1,49 +0,0 @@
1
- require 'cinch'
2
-
3
- module Cinch::Plugins
4
- class Convert
5
- include Cinch::Plugin
6
-
7
- self.help = "Use .convert <thing 1> to <thing 2> to do a unit conversion. (e.g. .convert 5 feet to meters)"
8
-
9
- match /convert (.+) to (.+)/
10
-
11
- def initialize(*args)
12
- super
13
- @units_path = config[:units_path] || '/usr/bin/units'
14
- end
15
-
16
- def execute(m, from, to)
17
- m.reply convert(from, to), true
18
- end
19
-
20
- private
21
-
22
- def convert(from, to)
23
- return "Sorry, there's a configuration issue." unless units_binary_exists?
24
-
25
- unless from.nil? || to.nil?
26
- units_output = IO.popen([@units_path, "-t", from, to])
27
-
28
- # we only take one line here because the first line of output is
29
- # either an error message or the part of the conversion output we
30
- # want.
31
- units_line = units_output.readline.chomp!
32
-
33
- if units_line.match(/Unknown unit/)
34
- "Sorry, #{units_line.downcase}."
35
- elsif units_line.match(/conformability error/)
36
- "Sorry, there was a conformability error when making that conversion."
37
- else
38
- "#{from} is #{units_line} #{to}."
39
- end
40
- end
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
48
- end
49
- end