irctc 0.0.1

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,21 @@
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
18
+ spec/
19
+ data/
20
+ conf/
21
+ tags
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in irctc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Prasanna N
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,57 @@
1
+ # Irctc
2
+
3
+ Ever spent time dumbly calculating when IRCTC.com will open ticket counter for
4
+ Diwali or some important festivals and holidays?
5
+
6
+ I did.
7
+
8
+ That's why I built this handy utility. Now don't miss any more money on
9
+ expensive "Redbuses"!
10
+
11
+ ## Installation
12
+
13
+ $ gem install irctc
14
+
15
+ ## Usage
16
+
17
+ It's a command-line awesomness.
18
+
19
+ To find when the counter opens for a future date, use the `-f` switch:
20
+
21
+ $ irctc -f 'nov 23, 2012'
22
+
23
+ Don't forget to book in '2' days!
24
+
25
+ For the given date, tickets are available from this date:
26
+ (Thu) Jul 26, 2012
27
+
28
+ $ irctc -f 'nov 13, 2012'
29
+
30
+ Ticket counter already opened '8' days ago.
31
+
32
+ For the given date, tickets are available from this date:
33
+ (Mon) Jul 16, 2012
34
+
35
+
36
+ To find for what future date the counter opens for the given date, use the
37
+ `-p` switch:
38
+
39
+ $ irctc -p 'jul 24, 2012'
40
+
41
+ On the given date, tickets are available for this date:
42
+ (Wed) Nov 21, 2012
43
+
44
+ Note: As of now, the irctc ticket counter opens **120 days** before the day you
45
+ need to travel.
46
+
47
+ ## Contributing
48
+
49
+ More awesome functionality can be added! For example, a gmail integration would
50
+ be great. It could send mail for the interested people for their preferred
51
+ days. I'm working on it already. Feel great to provide a helping hand.
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
+
6
+ require 'irctc'
7
+
8
+ options = Irctc::Command.parse ARGV
9
+ if Irctc::Command.validate
10
+ irctc_calc = Irctc::Calculator.new options
11
+ puts irctc_calc.calculate
12
+ else # good habit to not leave the else part
13
+ exit
14
+ end
15
+
16
+ # Example Usage
17
+ #
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/irctc/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Prasanna N"]
6
+ gem.email = ["prasann87@gmail.com"]
7
+ gem.description = %q{Handy utility to tell you when irctc's ticket counter opens}
8
+ gem.summary = %q{Given a date for which you want to book tickets, this tool will give you the day the irctc counter will open so you can book.
9
+
10
+ Given any current date, the tool will give the date for which irctc counter is opening for that date.}
11
+ gem.homepage = "https://github.com/npras/irctc"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "irctc"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Irctc::VERSION
19
+ gem.executables << 'irctc'
20
+ end
@@ -0,0 +1,8 @@
1
+ require "irctc/version"
2
+ require "irctc/command"
3
+ require "irctc/calculator"
4
+ require "date"
5
+
6
+ module Irctc
7
+ IRCTC_DAYS = 120
8
+ end
@@ -0,0 +1,32 @@
1
+ module Irctc
2
+ class Calculator
3
+
4
+ def initialize(opts)
5
+ @present_date = opts.present_date
6
+ @future_date = opts.future_date
7
+ end
8
+
9
+ def calculate
10
+ op = ''
11
+ # present
12
+ if @present_date
13
+ result = @present_date + IRCTC_DAYS
14
+ op += "\nOn the given date, tickets are available for this date:"
15
+ # future
16
+ elsif @future_date
17
+ result = @future_date - IRCTC_DAYS
18
+ days_left = (@future_date - Date.today).to_i - IRCTC_DAYS
19
+ if days_left <= 0
20
+ op += "\nTicket counter already opened '#{days_left.abs}' days ago."
21
+ else
22
+ op += "\nDon't forget to book in '#{days_left}' days!"
23
+ end
24
+ op += "\n\nFor the given date, tickets are available from this date:"
25
+ end
26
+
27
+ op += result.strftime("\n(%a) %b %d, %Y")
28
+ op
29
+ end
30
+
31
+ end # class Calculator
32
+ end # module Irctc
@@ -0,0 +1,55 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Irctc
5
+ class Command
6
+ #
7
+ # Return a structure describing the options.
8
+ #
9
+ def self.parse(args)
10
+ # The options specified on the cmd line will be collected in *options*.
11
+ # We set default values here.
12
+ @options = OpenStruct.new
13
+ @options.present_date = nil
14
+ @options.future_date = nil
15
+
16
+ opts = OptionParser.new do |opts|
17
+ opts.banner = "Usage: irctc OPTIONS"
18
+
19
+ opts.separator ""
20
+
21
+ opts.on("-p", "--present DATE",
22
+ "Which day's tickets are available for DATE?",
23
+ "Format(with quotes): 'July 2, 2012'") do |date|
24
+ @options.present_date = Date.parse date
25
+ end
26
+
27
+ opts.on("-f", "--future DATE",
28
+ "When will the counter open for the given DATE?",
29
+ "Format(with quotes): 'July 13, 2012'") do |date|
30
+ @options.future_date = Date.parse date
31
+ end
32
+
33
+ opts.separator ""
34
+ opts.separator "Common options:"
35
+
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ exit
39
+ end
40
+ end # OptionParser.new do
41
+
42
+ opts.parse!(args)
43
+ @options
44
+ end # parse()
45
+
46
+ def self.validate
47
+ if @options.present_date.nil? and @options.future_date.nil?
48
+ raise OptionParser::MissingArgument, "See --help."
49
+ else
50
+ true
51
+ end
52
+ end
53
+
54
+ end # class Command
55
+ end # module Irctc
@@ -0,0 +1,3 @@
1
+ module Irctc
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irctc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Prasanna N
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Handy utility to tell you when irctc's ticket counter opens
15
+ email:
16
+ - prasann87@gmail.com
17
+ executables:
18
+ - irctc
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/irctc
28
+ - irctc.gemspec
29
+ - lib/irctc.rb
30
+ - lib/irctc/calculator.rb
31
+ - lib/irctc/command.rb
32
+ - lib/irctc/version.rb
33
+ homepage: https://github.com/npras/irctc
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Given a date for which you want to book tickets, this tool will give you
57
+ the day the irctc counter will open so you can book. Given any current date, the
58
+ tool will give the date for which irctc counter is opening for that date.
59
+ test_files: []
60
+ has_rdoc: