Class: CoachZed::FeedReader
- Inherits:
-
Object
- Object
- CoachZed::FeedReader
- Defined in:
- lib/coach_zed/feed_reader.rb
Defined Under Namespace
Classes: Event
Instance Attribute Summary collapse
-
#feed_content ⇒ Object
readonly
Returns the value of attribute feed_content.
Class Method Summary collapse
Instance Method Summary collapse
- #events ⇒ Object
-
#initialize(feed_content) ⇒ FeedReader
constructor
A new instance of FeedReader.
- #last_date ⇒ Object
- #recent_events(limit_days: 28) ⇒ Object
- #to_context(limit_days: 28) ⇒ Object
Constructor Details
#initialize(feed_content) ⇒ FeedReader
Returns a new instance of FeedReader.
25 26 27 |
# File 'lib/coach_zed/feed_reader.rb', line 25 def initialize(feed_content) @feed_content = feed_content end |
Instance Attribute Details
#feed_content ⇒ Object (readonly)
Returns the value of attribute feed_content.
29 30 31 |
# File 'lib/coach_zed/feed_reader.rb', line 29 def feed_content @feed_content end |
Class Method Details
.load(path) ⇒ Object
17 18 19 |
# File 'lib/coach_zed/feed_reader.rb', line 17 def self.load(path) new(File.read(path.to_s)).events end |
.load_existing(path) ⇒ Object
21 22 23 |
# File 'lib/coach_zed/feed_reader.rb', line 21 def self.load_existing(path) new(File.read(path.to_s)) end |
Instance Method Details
#events ⇒ Object
31 32 33 |
# File 'lib/coach_zed/feed_reader.rb', line 31 def events @events ||= parse_events end |
#last_date ⇒ Object
35 36 37 |
# File 'lib/coach_zed/feed_reader.rb', line 35 def last_date events.map(&:date).compact.max end |
#recent_events(limit_days: 28) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/coach_zed/feed_reader.rb', line 39 def recent_events(limit_days: 28) last = last_date cutoff = last ? last - (limit_days - 1) : nil return events if cutoff.nil? events.select { |event| event.date && event.date >= cutoff } end |
#to_context(limit_days: 28) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/coach_zed/feed_reader.rb', line 47 def to_context(limit_days: 28) recent_events(limit_days:).map do |event| # @type var pieces: Array[String] pieces = [] pieces << event.date.iso8601 if event.date pieces << event.summary if event.summary && !event.summary.empty? pieces << event.description if event.description && !event.description.empty? pieces.join(" | ") end.join("\n") end |