polyrex-calendar 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/polyrex-calendar.rb +4 -7
  2. metadata +2 -2
@@ -11,7 +11,7 @@ class PolyrexCalendar
11
11
  attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
12
12
 
13
13
  def initialize(year=nil)
14
- @year = year ? year : Time.now.year
14
+ @year = year ? year.to_s : Time.now.year.to_s
15
15
  generate_calendar
16
16
  lib = File.dirname(__FILE__)
17
17
  @xsl = File.open(lib + '/calendar.xsl','r').read
@@ -65,11 +65,10 @@ class PolyrexCalendar
65
65
 
66
66
  def generate_calendar()
67
67
 
68
- d = Date.parse(@year.to_s + '-Jan-01')
69
- a = []
70
- (a << d; d += 1) while d.year == Time.now.year
68
+ a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a
71
69
 
72
70
  months = a.group_by(&:month).map do |key, month|
71
+
73
72
  i = month.index(month.detect{|x| x.wday == 0})
74
73
  unless i == 0 then
75
74
  weeks = [month.slice!(0,i)] + month.each_slice(7).to_a
@@ -78,9 +77,7 @@ class PolyrexCalendar
78
77
  weeks = month.each_slice(7).to_a
79
78
  end
80
79
 
81
- if weeks[-1].length < 7 then
82
- weeks[-1] = (weeks[-1] + [nil] * 6 ).slice(0,7)
83
- end
80
+ weeks[-1] = (weeks[-1] + [nil] * 6 ).slice(0,7) if weeks[-1].length < 7
84
81
 
85
82
  weeks
86
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrex-calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2011-01-23 00:00:00 +00:00
12
+ date: 2011-01-24 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency