Class: Calrom::Formatter::Json
- Inherits:
-
Object
- Object
- Calrom::Formatter::Json
- Defined in:
- lib/calrom/formatter/json.rb
Overview
JSON format mimicking Church Calendar API v0 (github.com/igneus/church-calendar-api)
Instance Method Summary collapse
Instance Method Details
#call(calendar, date_range) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/calrom/formatter/json.rb', line 7 def call(calendar, date_range) # We build the outer JSON Array manually in order to be able to print # vast amounts of calendar data without risking RAM exhaustion. print "[" date_range.each_with_index do |date, i| day = calendar[date] hash = { date: date, season: day.season.symbol, season_week: day.season_week, celebrations: day.celebrations.collect do |c| { title: c.title, symbol: c.symbol, colour: c.colour.symbol, rank: c.rank.short_desc, rank_num: c.rank.priority } end, weekday: date.strftime('%A'), } puts "," if i > 0 print JSON.generate hash end puts "]" end |