month 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ Manifest.txt
2
+ README.txt
3
+ changelog.txt
4
+ install.rb
5
+ lib/month.rb
6
+ rakefile
7
+ test/ts_month.rb
@@ -0,0 +1,7 @@
1
+ Ruby Month is a utility class for representing months in Ruby. It handles addition, previous and next months, end and start dates, month names (in English), and a few other handy things.
2
+
3
+ http://rubyforge.org/projects/month/
4
+
5
+ INSTALLATION:
6
+ As root, run "./install.rb", which will copy the Ruby files into the right
7
+ subdirectory. You can run "./install.rb --help" for information.
@@ -0,0 +1,9 @@
1
+ = 0.1.2 -- Nov 2 2007
2
+ * added Month#succ.
3
+
4
+ = 0.1.1 -- Jan 7 2007
5
+ * added install.rb
6
+ * added reference to Rubyforge project page to month.rb RDoc
7
+
8
+ = 0.1.0 -- Jun 7 2005
9
+ * Initial release.
@@ -0,0 +1,164 @@
1
+ #! /usr/bin/env ruby
2
+ ################################################################################
3
+ # #
4
+ # Name: install.rb #
5
+ # Author: Sean E Russell <ser@germane-software.com> #
6
+ # Version: $Id: install.rb,v 1.1 2007/01/08 01:46:57 francis Exp $
7
+ # Date: *2002-174 #
8
+ # Description: #
9
+ # This is a generic installation script for pure ruby sources. Features #
10
+ # include: #
11
+ # * Clean uninstall #
12
+ # * Installation into an absolute path #
13
+ # * Installation into a temp path (useful for systems like Portage) #
14
+ # * Noop mode, for testing #
15
+ # To set for a different system, change the SRC directory to point to the #
16
+ # package name / source directory for the project. #
17
+ # #
18
+ ################################################################################
19
+
20
+ # CHANGE THIS
21
+ SRC = 'lib'
22
+ MODULE_NAME = 'month'
23
+ BIN = 'bin'
24
+ # CHANGE NOTHING BELOW THIS LINE
25
+
26
+ if $0 == __FILE__
27
+ Dir.chdir ".." if Dir.pwd =~ /bin.?$/
28
+
29
+ require 'getoptlong'
30
+ require 'rbconfig'
31
+ require 'ftools'
32
+ require 'find'
33
+
34
+ opts = GetoptLong.new( [ '--uninstall', '-u', GetoptLong::NO_ARGUMENT],
35
+ [ '--destdir', '-d', GetoptLong::REQUIRED_ARGUMENT ],
36
+ [ '--target', '-t', GetoptLong::REQUIRED_ARGUMENT ],
37
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT],
38
+ [ '--noop', '-n', GetoptLong::NO_ARGUMENT])
39
+
40
+
41
+ destdir = File.join Config::CONFIG['sitedir'],
42
+ "#{Config::CONFIG['MAJOR']}.#{Config::CONFIG['MINOR']}"
43
+ bindir = '/usr/local/bin'
44
+
45
+ uninstall = false
46
+ append = nil
47
+ opts.each do |opt,arg|
48
+ case opt
49
+ when '--destdir'
50
+ append = arg
51
+ when '--uninstall'
52
+ uninstall = true
53
+ when '--target'
54
+ destdir = arg
55
+ when '--help'
56
+ puts "Installs #{SRC}.\nUsage:\n\t#$0 [[-u] [-n] [-t <dir>|-d <dir>]|-h]"
57
+ puts "\t-u --uninstall\tUninstalls the package"
58
+ puts "\t-t --target\tInstalls the software at an absolute location, EG:"
59
+ puts "\t #$0 -t /usr/local/lib/ruby"
60
+ puts "\t will put the software directly underneath /usr/local/lib/ruby;"
61
+ puts "\t IE, /usr/local/lib/ruby/#{SRC}"
62
+ puts "\t-d --destdir\tInstalls the software at a relative location, EG:"
63
+ puts "\t #$0 -d /tmp"
64
+ puts "\t will put the software under tmp, using your ruby environment."
65
+ puts "\t IE, /tmp/#{destdir}/#{SRC}"
66
+ puts "\t-n --noop\tDon't actually do anything; just print out what it"
67
+ puts "\t would do."
68
+ exit 0
69
+ when '--noop'
70
+ NOOP = true
71
+ end
72
+ end
73
+
74
+ destdir = File.join append, destdir if append
75
+
76
+ def get_install_base( file )
77
+ file_parts = file.split( File::SEPARATOR )
78
+ file_parts.shift
79
+ file_parts.join( File::SEPARATOR )
80
+ end
81
+
82
+ def install destdir, bindir
83
+ puts "Installing in #{destdir}"
84
+ begin
85
+ Find.find(SRC) { |file|
86
+ next if file =~ /CVS|\.svn/
87
+ install_base = get_install_base( file )
88
+ dst = File.join( destdir, install_base )
89
+ if defined? NOOP
90
+ puts ">> #{dst}" if file =~ /\.rb$/
91
+ else
92
+ File.makedirs( File.dirname(dst) )
93
+ File.install(file, dst, 0644, true) if file =~ /\.rb$/
94
+ end
95
+ }
96
+ rescue
97
+ puts $!
98
+ end
99
+ puts "Installing binaries in #{ bindir }"
100
+ begin
101
+ Dir.entries( BIN ).each { |entry|
102
+ src = File.join( BIN, entry )
103
+ next unless FileTest.executable?( src ) && !FileTest.directory?( src )
104
+ dst = File.join( bindir, entry )
105
+ if defined? NOOP
106
+ puts ">> #{ dst }"
107
+ else
108
+ File.install( src, dst, 0755, true )
109
+ end
110
+ }
111
+ rescue
112
+ puts $!
113
+ end
114
+ end
115
+
116
+ def uninstall destdir, bindir
117
+ puts "Uninstalling in #{destdir}"
118
+ begin
119
+ puts "Deleting:"
120
+ dirs = []
121
+ Find.find( destdir ) do |file|
122
+ if file =~ /^#{ destdir }#{ File::SEPARATOR }#{ MODULE_NAME }/
123
+ if defined? NOOP
124
+ puts "-- #{file}" if File.file? file
125
+ else
126
+ File.rm_f file,true if File.file? file
127
+ end
128
+ dirs << file if File.directory? file
129
+ end
130
+ end
131
+ dirs.sort { |x,y|
132
+ y.length <=> x.length
133
+ }.each { |d|
134
+ if defined? NOOP
135
+ puts "-- #{d}"
136
+ else
137
+ puts d
138
+ Dir.delete d
139
+ end
140
+ }
141
+ rescue
142
+ end
143
+ puts "Uninstalling binaries in #{ bindir }"
144
+ begin
145
+ Dir.entries( BIN ).each { |entry|
146
+ orig = File.join( BIN, entry )
147
+ next unless FileTest.executable?( orig ) && !FileTest.directory?( orig )
148
+ to_uninstall = File.join( bindir, entry )
149
+ if defined? NOOP
150
+ puts "-- #{to_uninstall}" if File.file? to_uninstall
151
+ else
152
+ File.rm_f to_uninstall,true if File.file? to_uninstall
153
+ end
154
+ }
155
+ rescue
156
+ end
157
+ end
158
+
159
+ if uninstall
160
+ uninstall destdir, bindir
161
+ else
162
+ install destdir, bindir
163
+ end
164
+ end
@@ -5,7 +5,7 @@
5
5
  # The Rubyforge project page can be viewed at
6
6
  # http://rubyforge.org/projects/month.
7
7
  class Month
8
- Version = '0.1.1'
8
+ Version = '0.1.2'
9
9
 
10
10
  # Returns an array of the full names of months (in English). Note that
11
11
  # "January" is the 0th element, and "December" is the 11th element.
@@ -79,6 +79,8 @@ class Month
79
79
  self + 1
80
80
  end
81
81
 
82
+ alias_method :succ, :next
83
+
82
84
  # Returns the previous Month.
83
85
  def prev
84
86
  self - 1
@@ -0,0 +1,44 @@
1
+ =begin
2
+ $: << 'lib'
3
+ require 'month'
4
+
5
+ @@version_str = Month::Version
6
+
7
+ def release_tag
8
+ ( uber, major, minor ) = @@version_str.split( '.' ).collect! { |str|
9
+ str.to_i
10
+ }
11
+ "rel-#{ uber }-#{ major }-#{ minor }"
12
+ end
13
+
14
+ def release_dir_name
15
+ "month-#{ @@version_str }"
16
+ end
17
+
18
+ task :export_release do
19
+ Dir.chdir('../releases')
20
+ ext = "-d:ext:francis@rubyforge.org:/var/cvs/month"
21
+ `cvs #{ ext } export -r #{ release_tag } -d #{ release_dir_name } month`
22
+ `tar zcvf month-#{ @@version_str }.tar.gz #{ release_dir_name }`
23
+ end
24
+
25
+ task :update_docs do
26
+ Dir.chdir( 'lib' )
27
+ `rdoc --op ../docs/`
28
+ end
29
+ =end
30
+
31
+ require 'hoe'
32
+ $:.unshift 'lib'
33
+ require 'month'
34
+
35
+ Hoe.new("month", Month::Version) do |p|
36
+ p.rubyforge_name = "month"
37
+ p.author = 'Francis Hwang'
38
+ p.description = p.paragraphs_of( 'README.txt', 0 ).first
39
+ p.summary = p.paragraphs_of( 'README.txt', 0 ).first
40
+ p.email = 'sera@fhwang.net'
41
+ p.url = 'http://month.rubyforge.org/'
42
+ p.changes = p.paragraphs_of( 'changelog.txt', 0 ).first
43
+ end
44
+
@@ -0,0 +1,68 @@
1
+ $: << 'lib'
2
+ require 'month'
3
+ require 'test/unit'
4
+
5
+ class TestMonth < Test::Unit::TestCase
6
+ def setup
7
+ @jan2000 = Month.new 2000, 1
8
+ @dec2000 = Month.new 2000, 12
9
+ @jan2001 = Month.new 2001, 1
10
+ end
11
+
12
+ def test_arithmetic
13
+ assert_equal( Month.new( 2000, 2 ), @jan2000 + 1 )
14
+ assert_equal( Month.new( 2001, 1 ), @jan2000 + 12 )
15
+ assert_equal( Month.new( 1999, 10 ), @jan2000 - 3 )
16
+ assert_equal( Month.new( 1999, 10 ), @jan2000 + -3 )
17
+ end
18
+
19
+ def test_checks_month
20
+ caught = false
21
+ begin
22
+ Month.new 1, 2000
23
+ rescue
24
+ caught = true
25
+ end
26
+ assert caught
27
+ Month.new 2000, 1
28
+ end
29
+
30
+ def test_compare
31
+ assert @jan2000 < @jan2001
32
+ end
33
+
34
+ def test_default_init_to_current_month
35
+ month = Month.new
36
+ date = Date.today
37
+ assert_equal( date.mon, month.month )
38
+ assert_equal( date.year, month.year )
39
+ end
40
+
41
+ def test_hashable
42
+ newJan2000 = Month.new( 2000, 1 )
43
+ assert_equal @jan2000, newJan2000
44
+ assert_equal @jan2000.hash, newJan2000.hash
45
+ assert( @jan2000.eql?( newJan2000 ) )
46
+ normalHash = {}
47
+ normalHash[@jan2000] = 'q'
48
+ assert_equal 'q', normalHash[newJan2000]
49
+ end
50
+
51
+ def test_prev_next_succ
52
+ assert_equal( @dec2000, @jan2001.prev )
53
+ assert_equal( @jan2001, @dec2000.next )
54
+ assert_equal( @jan2001, @dec2000.succ )
55
+ assert_equal( @jan2000, @jan2000.prev.next )
56
+ assert_equal( @jan2000, @jan2000.prev.succ )
57
+ end
58
+
59
+ def test_start_date_and_end_date
60
+ assert_equal( Date.new( 2000, 12, 1 ), @dec2000.start_date )
61
+ assert_equal( Date.new( 2000, 12, 31 ), @dec2000.end_date )
62
+ assert_equal( Date.new( 1999, 2, 28 ), Month.new( 1999, 2 ).end_date )
63
+ end
64
+
65
+ def test_to_s
66
+ assert_equal 'Jan 2000', @jan2000.to_s
67
+ end
68
+ end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: month
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2007-01-07 00:00:00 -05:00
8
- summary: Month is a utility class for representing months in Ruby.
6
+ version: 0.1.2
7
+ date: 2007-11-02 00:00:00 -04:00
8
+ summary: Ruby Month is a utility class for representing months in Ruby. It handles addition, previous and next months, end and start dates, month names (in English), and a few other handy things.
9
9
  require_paths:
10
10
  - lib
11
11
  email: sera@fhwang.net
12
12
  homepage: http://month.rubyforge.org/
13
- rubyforge_project:
13
+ rubyforge_project: month
14
14
  description: Ruby Month is a utility class for representing months in Ruby. It handles addition, previous and next months, end and start dates, month names (in English), and a few other handy things.
15
- autorequire: month
15
+ autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
- has_rdoc: false
18
+ has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
21
  - - ">"
@@ -25,22 +25,39 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Francis Hwang
30
31
  files:
32
+ - Manifest.txt
33
+ - README.txt
34
+ - changelog.txt
35
+ - install.rb
31
36
  - lib/month.rb
32
- - lib/month.rb~
37
+ - rakefile
38
+ - test/ts_month.rb
33
39
  test_files: []
34
40
 
35
- rdoc_options: []
36
-
37
- extra_rdoc_files: []
38
-
41
+ rdoc_options:
42
+ - --main
43
+ - README.txt
44
+ extra_rdoc_files:
45
+ - Manifest.txt
46
+ - README.txt
47
+ - changelog.txt
39
48
  executables: []
40
49
 
41
50
  extensions: []
42
51
 
43
52
  requirements: []
44
53
 
45
- dependencies: []
46
-
54
+ dependencies:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ version_requirement:
58
+ version_requirements: !ruby/object:Gem::Version::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.3.0
63
+ version:
@@ -1,93 +0,0 @@
1
- # Month represents a specific month in time. With the exception of
2
- # Month.month_names (which returns a zero-based array), every usage of the
3
- # month value assumes that 1 equals January and 12 equals December.
4
- class Month
5
- Version = '0.1.0'
6
-
7
- # Returns an array of the full names of months (in English). Note that
8
- # "January" is the 0th element, and "December" is the 11th element.
9
- def Month.month_names
10
- [ "January", "February", "March", "April", "May", "June", "July",
11
- "August", "September", "October", "November", "December" ]
12
- end
13
-
14
- include Comparable
15
-
16
- attr_reader :month, :year
17
-
18
- # A new month can be set to a specific +month+ and +year+, or you can call
19
- # Month.new with no arguments to receive the current month.
20
- def initialize( year = nil, month = nil )
21
- require 'date'
22
- if month.nil? || year.nil?
23
- date = Date.today
24
- month = date.mon unless month
25
- year = date.year unless year
26
- end
27
- fail "invalid month" if month < 1 || month > 12
28
- @month = month
29
- @year = year
30
- end
31
-
32
- # Returns a new Month that is +amountToAdd+ months later.
33
- def +( amountToAdd )
34
- ( fullYears, remainingMonths ) = amountToAdd.divmod( 12 )
35
- resultYear = @year + fullYears
36
- resultMonth = @month + remainingMonths
37
- if resultMonth > 12
38
- resultMonth -= 12
39
- resultYear += 1
40
- end
41
- Month.new( resultYear, resultMonth )
42
- end
43
-
44
- # Returns a new Month that is +amountToSubtract+ months earlier.
45
- def -(amountToSubtract)
46
- self + (-amountToSubtract)
47
- end
48
-
49
- # Compare this Month to another Month.
50
- def <=>(anOther)
51
- if @year == anOther.year
52
- @month <=> anOther.month
53
- else
54
- @year <=> anOther.year
55
- end
56
- end
57
-
58
- # Returns the last Date of the month.
59
- def end_date
60
- self.next.start_date - 1
61
- end
62
-
63
- # Is this Month equal to +anOther+? +anOther+ must be another Month of the
64
- # same value.
65
- def eql?(anOther)
66
- self == anOther
67
- end
68
-
69
- # Calculate a hash value for this Month.
70
- def hash
71
- "#{@year}#{@month}".to_i
72
- end
73
-
74
- # Returns the next Month.
75
- def next
76
- self + 1
77
- end
78
-
79
- # Returns the previous Month.
80
- def prev
81
- self - 1
82
- end
83
-
84
- # Returns the first Date of the month.
85
- def start_date
86
- Date.new( @year, @month, 1 )
87
- end
88
-
89
- # Returns a string of the format "January 2001".
90
- def to_s
91
- Month.month_names[@month-1][0..2] + " " + @year.to_s
92
- end
93
- end