Skip to content

Commit

Permalink
v1.0.9 - spec refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaberer committed Aug 1, 2014
1 parent c3077e3 commit efbdfd6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 86 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ rvm:
- 1.8.7
- jruby-18mode
- jruby-19mode
- rbx
- ruby-head
- jruby-head
- ree
Expand Down
23 changes: 11 additions & 12 deletions cinch-pax-timer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ Gem::Specification.new do |gem|
gem.version = Cinch::Plugins::PaxTimer::VERSION
gem.authors = ['Brian Haberer']
gem.email = ['bhaberer@gmail.com']
gem.description = %q{Cinch plugin that allows users to see the relative time till the various PAX events}
gem.summary = %q{Cinch Plugin that acts as a PAX countdown}
gem.description = %q(Cinch plugin that allows users to see the relative time till the various PAX events)
gem.summary = %q(Cinch Plugin that acts as a PAX countdown)
gem.homepage = 'https://github.com/bhaberer/cinch-pax-timer'
gem.license = 'MIT'

gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
gem.require_paths = ['lib']

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'coveralls'
gem.add_development_dependency 'cinch-test'

gem.add_dependency 'cinch-cooldown', '~> 1.1.1'
gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
gem.add_development_dependency 'rake', '~> 10'
gem.add_development_dependency 'rspec', '~> 3'
gem.add_development_dependency 'coveralls', '~> 0.7'
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.0'
gem.add_dependency 'cinch', '~> 2'
gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.1'
gem.add_dependency 'cinch-toolbox', '~> 1.1'
end
114 changes: 58 additions & 56 deletions lib/cinch/plugins/pax-timer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,79 @@
require 'cinch/toolbox'
require 'cinch/cooldown'

module Cinch::Plugins
# Cinch Cooldown for PAX countdowns
class PaxTimer
include Cinch::Plugin
module Cinch
module Plugins
# Cinch Cooldown for PAX countdowns
class PaxTimer
include Cinch::Plugin

enforce_cooldown
enforce_cooldown

self.help = 'Use .pax for the next pax or .east, .prime, .south or .aus ' +
'for the time to a specific pax.'
self.help = 'Use .pax for the next pax or .east, .prime, .south or ' \
'.aus for the time to a specific pax.'

match /pax\z/, method: :next_pax
match(/pax\z/, method: :next_pax)

def next_pax(m)
m.reply get_next_pax
end
def next_pax(m)
m.reply get_next_pax
end

PAXES = [
{ type: 'aus',
name: 'PAX Australia',
date: Time.parse('2014-10-31 08:00:00 +11:00'),
estimated: false },
{ type: 'prime',
name: 'PAX Prime',
date: Time.parse('2014-08-29 08:00:00 -08:00'),
estimated: false },
{ type: 'south',
name: 'PAX South',
date: Time.parse('2015-01-23 08:00:00 -06:00'),
estimated: false },
{ type: 'east',
name: 'PAX East',
date: Time.parse('2015-03-06 08:00:00 -05:00'),
estimated: false }
]

PAXES.map { |p| p[:type] }.each do |pax|
match /(#{pax}|pax#{pax})\z/, method: "next_#{pax}"

define_method "next_#{pax}" do |m|
debug "#{pax}"
m.reply get_next_pax(pax.to_s)
PAXES = [
{ type: 'aus',
name: 'PAX Australia',
date: Time.parse('2014-10-31 08:00:00 +11:00'),
estimated: false },
{ type: 'prime',
name: 'PAX Prime',
date: Time.parse('2014-08-29 08:00:00 -08:00'),
estimated: false },
{ type: 'south',
name: 'PAX South',
date: Time.parse('2015-01-23 08:00:00 -06:00'),
estimated: false },
{ type: 'east',
name: 'PAX East',
date: Time.parse('2015-03-06 08:00:00 -05:00'),
estimated: false }
]

PAXES.map { |p| p[:type] }.each do |pax|
match(/(#{pax}|pax#{pax})\z/, method: "next_#{pax}")

define_method "next_#{pax}" do |m|
debug "#{pax}"
m.reply get_next_pax(pax.to_s)
end
end
end

private
private

def get_next_pax(type = nil)
@pax = get_next_pax_for(type)
def get_next_pax(type = nil)
@pax = get_next_pax_for(type)

return 'I don\'t have info for the next one of those PAXes' if @pax.nil?
return 'I don\'t have info for the next one of those PAXes' if @pax.nil?

message = ["#{@pax[:name]} is"]
message << 'approximately' if @pax[:estimated]
message = ["#{@pax[:name]} is"]
message << 'approximately' if @pax[:estimated]

# Uncomment this once we can specify granularity in Time Lord.
# message << TimeLord::Period.new(@pax[:date], Time.now).to_words
message << Cinch::Toolbox.time_format(@pax[:date] - Time.now, [:days])
message << 'from now'
# Uncomment this once we can specify granularity in Time Lord.
# message << TimeLord::Period.new(@pax[:date], Time.now).to_words
message << Cinch::Toolbox.time_format(@pax[:date] - Time.now, [:days])
message << 'from now'

message << ' (No official date, yet)' if @pax[:estimated]
message.join(' ')
end
message << ' (No official date, yet)' if @pax[:estimated]
message.join(' ')
end

def get_next_pax_for(type)
paxes = PAXES.dup
def get_next_pax_for(type)
paxes = PAXES.dup

paxes.delete_if { |pax| pax[:date] - Time.now < 0 }
paxes.delete_if { |pax| pax[:type] != type } unless type.nil?
paxes.sort! { |a, b| b[:date] <=> a[:date] }
paxes.delete_if { |pax| pax[:date] - Time.now < 0 }
paxes.delete_if { |pax| pax[:type] != type } unless type.nil?
paxes.sort! { |a, b| b[:date] <=> a[:date] }

paxes.last
paxes.last
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cinch/plugins/pax-timer/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Cinch
module Plugins
# Versioning info
class PaxTimer
VERSION = '1.0.8'
VERSION = '1.0.9'
end
end
end
31 changes: 15 additions & 16 deletions spec/cinch-pax-timer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,49 @@
describe :pax do
it 'should return the next pax' do
msg = make_message(@bot, '!pax')
get_replies(msg).first.text.
should match(/PAX.+is (approximatly )?\d+ days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX.+is (approximatly )?\d+ days from now/)
end

it 'should return nothing if there are arguments' do
msg = make_message(@bot, '!pax fail')
get_replies(msg).first.
should be_nil
expect(get_replies(msg).first).to be_nil
end
end

it 'should respond to .prime correctly' do
msg = make_message(@bot, '!prime')
get_replies(msg).first.text.
should match(/PAX Prime is.+days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX Prime is.+days from now/)
end

it 'should respond to .paxprime correctly' do
msg = make_message(@bot, '!paxprime')
get_replies(msg).first.text.
should match(/PAX Prime is.+days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX Prime is.+days from now/)
end

it 'should respond to .east correctly' do
msg = make_message(@bot, '!east')
get_replies(msg).first.text.
should match(/PAX East is.+days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX East is.+days from now/)
end

it 'should respond to .paxeast correctly' do
msg = make_message(@bot, '!paxeast')
get_replies(msg).first.text.
should match(/PAX East is.+days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX East is.+days from now/)
end

it 'should respond to .aus correctly' do
msg = make_message(@bot, '!aus')
get_replies(msg).first.text.
should match(/PAX Australia is.+days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX Australia is.+days from now/)
end

it 'should respond to .paxaus correctly' do
msg = make_message(@bot, '!paxaus')
get_replies(msg).first.text.
should match(/PAX Australia is.+days from now/)
msg = get_replies(msg).first
expect(msg.text).to match(/PAX Australia is.+days from now/)
end
end

0 comments on commit efbdfd6

Please sign in to comment.