class Almanack::Representation::JSONFeed

Attributes

calendar[R]

Public Class Methods

from(calendar) click to toggle source
# File lib/almanack/representation/json_feed.rb, line 16
def self.from(calendar)
  self.new(calendar)
end
new(calendar) click to toggle source
# File lib/almanack/representation/json_feed.rb, line 6
def initialize(calendar)
  @calendar = calendar
end

Public Instance Methods

to_s() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 10
def to_s
  json_friendly = SerializedTransformation.new(serialized)
  json_friendly.key { |key| camelize(key.to_s) }
  json_friendly.apply.to_json
end

Private Instance Methods

camelize(string) click to toggle source
# File lib/almanack/representation/json_feed.rb, line 22
def camelize(string)
  string.split('_').map.with_index do |part, index|
    index.zero? ? part : part.capitalize
  end.join
end
date_range() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 28
def date_range
  now..lookahead
end
event_sources() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 42
def event_sources
  calendar.event_sources
end
lookahead() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 46
def lookahead
  now + calendar.feed_lookahead * ONE_DAY
end
now() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 50
def now
  @now ||= Time.now
end
serialized() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 32
def serialized
  { event_sources: serialized_event_sources }
end
serialized_event_sources() click to toggle source
# File lib/almanack/representation/json_feed.rb, line 36
def serialized_event_sources
  event_sources.map do |source|
    source.serialized_between(date_range)
  end
end