aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Goce <carlosgoce@gmail.com>2015-01-23 18:13:02 +0100
committerCarlos Goce <carlosgoce@gmail.com>2015-01-23 18:13:02 +0100
commite1a70c37b11cb893a126784cc3d94b01f7c6c041 (patch)
tree149d81420657a3dec9eed5095bfbc39b9fd0faeb
parent19c3ee5ebc960618241132effde30d74ccc1a478 (diff)
downloadpdf-calendars-e1a70c37b11cb893a126784cc3d94b01f7c6c041.tar.gz
pdf-calendars-e1a70c37b11cb893a126784cc3d94b01f7c6c041.tar.bz2
pdf-calendars-e1a70c37b11cb893a126784cc3d94b01f7c6c041.zip
Refactor data structure
-rw-r--r--lib/carlosgoce/calendar.rb9
-rw-r--r--spec/calendar_spec.rb8
2 files changed, 8 insertions, 9 deletions
diff --git a/lib/carlosgoce/calendar.rb b/lib/carlosgoce/calendar.rb
index 5ac27b0..74051d3 100644
--- a/lib/carlosgoce/calendar.rb
+++ b/lib/carlosgoce/calendar.rb
@@ -11,12 +11,11 @@ module CarlosGoce
end
def to_h
- Hash.new.tap {|bar|
+ Hash.new.tap {|h|
(1..12).each do |month|
- month_name = I18n.t('date.month_names')[month].downcase
- month_days =(1...Time.days_in_month(month, @year)).to_a.each_slice(7).to_a
-
- bar[month_name] = month_days
+ h[month] = {}
+ h[month][:days] = (1...Time.days_in_month(month, @year)).to_a.each_slice(7).to_a
+ h[month][:name] = I18n.t('date.month_names')[month].downcase
end
}
end
diff --git a/spec/calendar_spec.rb b/spec/calendar_spec.rb
index 71252b3..e7fe00b 100644
--- a/spec/calendar_spec.rb
+++ b/spec/calendar_spec.rb
@@ -14,15 +14,15 @@ describe 'Calendar' do
expect(@calendar.year).to eq(Date.today.year)
end
- describe 'Return months and days of given year' do
+ describe 'Return a data structure with all needed data to generate a pdf' do
it 'should have all months of the year' do
expect(@calendar.to_h.count).to eq(12)
end
- it 'localize month names' do
- expect(@calendar.to_h.keys.first.to_s).to eq('january')
+ it 'return month names localized' do
+ expect(@calendar.to_h[1][:name]).to eq('january')
I18n.locale = 'es'
- expect(@calendar.to_h.keys.first.to_s).to eq('enero')
+ expect(@calendar.to_h[1][:name]).to eq('enero')
end
end
end \ No newline at end of file