weekday 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ == 1.0.2 / 2011-02-23
2
+
3
+ * 1 bugfix
4
+ * better error messages if no arguments where given
5
+ * 3 enhancements
6
+ * new method Weekday.sundays(2011)
7
+ * new method Weekday.first_monday(2011)
8
+ * new method Weekday.last_tuesday(2011)
9
+
1
10
  == 1.0.1 / 2011-02-15
2
11
 
3
12
  * Documentation
data/examples/termine.rb CHANGED
@@ -1,16 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
 
3
4
  require 'rubygems'
4
5
  require 'weekday' # Weekday-Gem
5
6
  require 'date'
6
7
 
7
- class Weekday
8
- COUNTWORDS = %w(erster zweiter dritter vierter f�nfter)
9
- DAYNAMES = %w(sonntag montag dienstag mittwoch donnerstag freitag samstag)
10
- DAYNAMESS = %w(sonntage montage dienstage mittwoche donnerstage freitage samstage)
11
- end # class Weekday
12
-
13
8
  NEXTDAYS = ['heute','morgen','uebermorgen']
9
+ PREVDAYS = ['gestern']
14
10
 
15
11
  def heute?(day)
16
12
  t = Time.now
@@ -25,11 +21,16 @@ def uebermorgen?(day)
25
21
  morgen? day-1
26
22
  end
27
23
 
24
+ def gestern?(day)
25
+ heute? day+1
26
+ end
27
+
28
28
  def puts_event(day,text,condition)
29
29
  if condition
30
30
  print NEXTDAYS[0]+", " if heute? day
31
31
  print NEXTDAYS[1]+", " if morgen? day
32
32
  print NEXTDAYS[2]+", " if uebermorgen? day
33
+ print PREVDAYS[0]+", " if gestern? day
33
34
  puts "#{day.day}.#{day.month}.#{day.year}"
34
35
  puts text
35
36
  puts
@@ -43,7 +44,7 @@ reichweite = ARGV[0].to_i if ARGV[0]
43
44
  ueberschrift = "Termine in den naechsten #{reichweite} Tagen"
44
45
  puts ueberschrift
45
46
  puts '-'*ueberschrift.length
46
- reichweite.times do
47
+ -1.upto(reichweite-1) do
47
48
  year = tag.year
48
49
  month = tag.month
49
50
  puts_event tag, "Blue Moon Freie Themenwahl (jeden 2. Di)", Weekday.second_tuesday(year,month) == tag
data/lib/wd.rb CHANGED
@@ -5,13 +5,11 @@ module Weekday
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # Returns the version string for the library.
8
- # :startdoc:
9
8
 
10
9
  def self.version
11
10
  @version ||= File.read(path('version.txt')).strip
12
11
  end
13
12
 
14
- # :stopdoc:
15
13
  # Returns the library path for the module. If any arguments are given,
16
14
  # they will be joined to the end of the libray path using
17
15
  # <tt>File.join</tt>.
data/lib/weekday.rb CHANGED
@@ -30,10 +30,22 @@ If a certain date like 'fifth_saturday' is not possible, nil is returned.
30
30
  # * Weekday.last_monday(2010,11)
31
31
  # The return value is a date object or nil if there is no Nth Xday in this month
32
32
  # * Weekday.mondays(2011,2) returns an array of all mondays in this month
33
+ # * Weekday.first_monday(2011) returns the very first monday in this year
34
+ # * Weekday.last_monday(2011) returns the very last monday in this year
35
+ # * Weekday.mondays(2011) returns all mondays in this year as an array of Date objects
33
36
  def self.method_missing(m, *args)
34
37
  # self.mondays .. self.sundays
35
38
  if DAYNAMESS.include?(m.to_s)
36
39
  wnum = DAYNAMESS.index(m.to_s)
40
+ raise ArgumentError, ILLEGAL_ARGUMENTS unless args[0] or args[1]
41
+ # mondays .. sundays without a month => calculate complete year
42
+ unless args[1]
43
+ result = []
44
+ 1.upto(12) do |mm|
45
+ result = (result + self.send(m,args[0],mm)).flatten
46
+ end
47
+ return result
48
+ end
37
49
  begin
38
50
  d = Date.new(args[0],args[1])
39
51
  rescue ArgumentError
@@ -64,6 +76,8 @@ If a certain date like 'fifth_saturday' is not possible, nil is returned.
64
76
  end
65
77
  # self.last_monday .. self.last_sunday
66
78
  if count == COUNTWORDS.index(COUNTWORDS[-1])+1
79
+ args[1] = 12 if args[1] == nil # december if no month was given at
80
+ # last_xxx(year)
67
81
  d = Date.new(args[0],args[1],-1)
68
82
  while not d.wday == wnum do
69
83
  d -= 1
@@ -72,6 +86,10 @@ If a certain date like 'fifth_saturday' is not possible, nil is returned.
72
86
  end
73
87
  case count
74
88
  when 1
89
+ # at least a year must be given
90
+ raise ArgumentError, ILLEGAL_ARGUMENTS unless args[0] or args[1]
91
+ args[1] = 1 if args[1] == nil # january if no month was given at
92
+ # first_xxx(year)
75
93
  begin
76
94
  d = Date.new(args[0],args[1],1)
77
95
  rescue ArgumentError
data/test/test_wd.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require './lib/weekday'
2
2
  require 'test/unit'
3
3
 
4
- class TestSamstag < Test::Unit::TestCase
4
+ class TestWd < Test::Unit::TestCase
5
5
  def test_class
6
6
  assert_equal Date, Weekday.first_saturday(2010,12).class
7
7
  end
@@ -122,5 +122,34 @@ class TestSamstag < Test::Unit::TestCase
122
122
  assert_nil Weekday.first_monday(2010,20)
123
123
  }
124
124
  end
125
+
126
+ def test_no_arguments_given
127
+ assert_raises(ArgumentError) {
128
+ assert_nil Weekday.first_monday
129
+ }
130
+ assert_raises(ArgumentError) {
131
+ assert_nil Weekday.mondays
132
+ }
133
+ end
134
+
135
+ def test_first_in_a_year
136
+ assert_equal(Weekday.first_monday(2011,1),
137
+ Weekday.first_monday(2011))
138
+ end
139
+
140
+ def test_last_in_a_year
141
+ assert_equal(Weekday.last_monday(2011,12),
142
+ Weekday.last_monday(2011))
143
+ end
144
+
145
+ def test_all_mondays_in_a_year
146
+ mondays = []
147
+ 1.upto 12 do |m|
148
+ mondays << Weekday.mondays(2011,m)
149
+ end
150
+ mondays.flatten!
151
+ assert_equal(mondays, Weekday.mondays(2011))
152
+ end
153
+
125
154
  end
126
155
 
data/version.txt CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Thomas Preymesser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-16 00:00:00 +01:00
17
+ date: 2011-02-23 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency