Class: FindSubscriptions::Output::JsonReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/output/json_reporter.rb

Overview

Outputs subscriptions as a pretty-printed JSON array.

Instance Method Summary collapse

Constructor Details

#initialize(io: $stdout) ⇒ JsonReporter

Returns a new instance of JsonReporter.



9
10
11
# File 'lib/output/json_reporter.rb', line 9

def initialize(io: $stdout)
  @io = io
end

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/output/json_reporter.rb', line 13

def print(subscriptions)
  data = subscriptions.map do |sub|
    {
      name: sub[:name],
      amount: sub[:amount],
      since: sub[:since].iso8601,
      until: sub[:until].iso8601,
      count: sub[:count]
    }
  end
  @io.puts JSON.pretty_generate(data)
end