Module: SimpleFeed::DSL::Formatter

Includes:
SimpleFeed::DSL
Included in:
Activities
Defined in:
lib/simplefeed/dsl/formatter.rb

Overview

This module exports method #color_dump which receives an activity and then prints out a report about the activity, including the event data found for a given user.

Constant Summary

Constants included from SimpleFeed::DSL

TIME_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleFeed::DSL

#_hr, #_print, #_puts, debug?, #event, #field, #field_label, #field_value, #header, #hr, #with_activity

Instance Attribute Details

#activityObject

Returns the value of attribute activity.



12
13
14
# File 'lib/simplefeed/dsl/formatter.rb', line 12

def activity
  @activity
end

#feedObject

Returns the value of attribute feed.



12
13
14
# File 'lib/simplefeed/dsl/formatter.rb', line 12

def feed
  @feed
end

Instance Method Details

#color_dump(this_activity = activity) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/simplefeed/dsl/formatter.rb', line 14

def color_dump(this_activity = activity)
  this_activity = if this_activity.is_a?(SimpleFeed::Activity::SingleUser)
                this_activity.feed.activity([this_activity.user_id])
              else
                this_activity
              end
  _puts

  header do
    field('Feed Name', feed.name, "\n")
    field('Provider', feed.provider.provider.class, "\n")
    field('Max Size', feed.max_size, "\n")
  end

  with_activity(this_activity) do
    this_activity.each do |user_id|
      this_last_event_at = nil
      this_last_read     = (last_read[user_id] || 0.0).to_f

      [['User ID', user_id, "\n"],
       ['Activities', sprintf('%d total, %d unread', total_count[user_id], unread_count[user_id]), "\n"],
       ['Last Read', this_last_read ? Time.at(this_last_read) : 'N/A'],
      ].each do |field, value, *args|
        field(field, value, *args)
      end

      _puts; hr 'ยจ'

      this_events       = fetch[user_id]
      this_events_count = this_events.size
      this_events.each_with_index do |_event, _index|

        if this_last_event_at.nil? && _event.at < this_last_read
          print_last_read_separator(this_last_read)
        elsif this_last_event_at && this_last_read < this_last_event_at && this_last_read > _event.at
          print_last_read_separator(this_last_read)
        end

        this_last_event_at = _event.at # float
        _print "[%2d] %16s %s\n", _index, _event.time.strftime(TIME_FORMAT).blue.bold, _event.value
        if _index == this_events_count - 1 && this_last_read < _event.at
          print_last_read_separator(this_last_read)
        end
      end
    end
  end
end


62
63
64
# File 'lib/simplefeed/dsl/formatter.rb', line 62

def print_last_read_separator(lr)
  _print ">>>> %16s <<<< last read\n", Time.at(lr).strftime(TIME_FORMAT).red.bold
end