next_bus 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in next_bus.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'pry'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dave Elliott
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,35 @@
1
+ # NextBus
2
+
3
+ Simple ruby gem to tell me when the next X40 bus is.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'next_bus'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install next_bus
18
+
19
+ ## Usage
20
+
21
+ $ next_bus [OPTIONS]
22
+
23
+ Options
24
+ * -m or --mins # Minutes till next bus
25
+ * -a or --all # List all available buses
26
+ * -h or --help # Show this message
27
+
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require 'next_bus'
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ puts NextBus.run(*ARGV)
@@ -0,0 +1,38 @@
1
+ require "next_bus/version"
2
+ require "next_bus/bus_times"
3
+
4
+ module NextBus
5
+ BUS_TIMES = %w{1615 1637 1657 1707 1717 1737 1745 1805 1825 1845 1905}
6
+
7
+ def self.run(*args)
8
+ bus_times = BusTimes.new(BUS_TIMES)
9
+
10
+ if args.include?('-a') || args.include?('--all')
11
+ if list = bus_times.list
12
+ 'Next bus times: ' + list.join(', ')
13
+ else
14
+ 'There are no more buses today.'
15
+ end
16
+ elsif args.include?('-m') || args.include?('--mins')
17
+ if mins_until = bus_times.mins_till
18
+ "Next bus is in #{mins_until} mins."
19
+ else
20
+ 'There are no more buses today.'
21
+ end
22
+ elsif args.length == 0
23
+ if next_bus = bus_times.next_bus
24
+ "Next bus is at #{next_bus}"
25
+ else
26
+ 'There are no more buses today.'
27
+ end
28
+ else
29
+ 'Usage:
30
+ next_bus [OPTIONS]
31
+
32
+ Options:
33
+ -m, [--mins] # Minutes till next bus
34
+ -a, [--all] # List all available buses
35
+ -h, [--help] # Show this message'
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ module NextBus
2
+ class BusTimes
3
+ attr_reader :times
4
+
5
+ def initialize(bus_times)
6
+ @times = bus_times.sort!
7
+ end
8
+
9
+ def next_bus
10
+ temp_times = self.times.dup
11
+ temp_times << time_now
12
+ temp_times.sort!
13
+
14
+ index = temp_times.index(time_now)
15
+ self.times[index]
16
+ end
17
+
18
+ def list
19
+ temp_times = self.times.dup
20
+
21
+ temp_times << time_now
22
+ temp_times.sort!
23
+
24
+ index = temp_times.index(time_now)
25
+ from = times.length - index
26
+ times[-from..from] if from > 0
27
+ end
28
+
29
+ def mins_till
30
+ n_bus = next_bus
31
+ n_bus.to_i - time_now.to_i if n_bus
32
+ end
33
+
34
+ private
35
+
36
+ def time_now
37
+ time = Time.now.strftime("%k%M")
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module NextBus
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'next_bus/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "next_bus"
8
+ gem.version = NextBus::VERSION
9
+ gem.authors = ["Dave Elliott"]
10
+ gem.email = ["ddazza@gmail.com"]
11
+ # gem.description = ''
12
+ gem.summary = 'Ouputs the time until the next bus'
13
+ gem.homepage = "https://github.com/DDAZZA/next_bus.git"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+ require 'time'
3
+
4
+ describe NextBus do
5
+ describe :run do
6
+ context 'when run with -h param' do
7
+ let(:help) do
8
+ 'Usage:
9
+ next_bus [OPTIONS]
10
+
11
+ Options:
12
+ -m, [--mins] # Minutes till next bus
13
+ -a, [--all] # List all available buses
14
+ -h, [--help] # Show this message'
15
+ end
16
+
17
+ it 'returns usage info' do
18
+ described_class.run('-h').should == help
19
+ end
20
+ end
21
+
22
+ context 'when the time is 11pm' do
23
+ before :each do
24
+ time = Time.parse('23:00')
25
+ Time.stub(:now).and_return(time)
26
+ end
27
+
28
+ context 'with no params' do
29
+ it 'returns the next bus time' do
30
+ described_class.run.should == 'There are no more buses today.'
31
+ end
32
+ end
33
+
34
+ context 'with -a param' do
35
+ it 'returns bus times' do
36
+ described_class.run('-a').should == 'There are no more buses today.'
37
+ end
38
+ end
39
+
40
+ context 'with -m param' do
41
+ it 'returns bus times' do
42
+ described_class.run('-m').should == 'There are no more buses today.'
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'when the time is 5pm' do
48
+ before :each do
49
+ time = Time.parse('17:00')
50
+ Time.stub(:now).and_return(time)
51
+ end
52
+
53
+ context 'with no params' do
54
+ it 'returns the next bus time' do
55
+ described_class.run.should == 'Next bus is at 1707'
56
+ end
57
+ end
58
+
59
+ context 'with -a param' do
60
+ it 'returns bus times' do
61
+ described_class.run('-a').should == 'Next bus times: 1707, 1717, 1737, 1745, 1805, 1825'
62
+ end
63
+ end
64
+
65
+ context 'with -m param' do
66
+ it 'returns bus times' do
67
+ described_class.run('-m').should == 'Next bus is in 7 mins.'
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'next_bus'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: next_bus
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Elliott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - ddazza@gmail.com
17
+ executables:
18
+ - next_bus
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .rspec
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/next_bus
29
+ - lib/next_bus.rb
30
+ - lib/next_bus/bus_times.rb
31
+ - lib/next_bus/version.rb
32
+ - next_bus.gemspec
33
+ - spec/next_bus_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage: https://github.com/DDAZZA/next_bus.git
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Ouputs the time until the next bus
59
+ test_files:
60
+ - spec/next_bus_spec.rb
61
+ - spec/spec_helper.rb
62
+ has_rdoc: