Class: Yudachi::SlackNotifier
- Inherits:
-
Object
- Object
- Yudachi::SlackNotifier
- Defined in:
- lib/yudachi/slack_notifier.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ SlackNotifier
constructor
A new instance of SlackNotifier.
- #notify(datapoints:, location_name:) ⇒ Object
Constructor Details
#initialize(url) ⇒ SlackNotifier
Returns a new instance of SlackNotifier.
5 6 7 |
# File 'lib/yudachi/slack_notifier.rb', line 5 def initialize(url) @url = url end |
Instance Method Details
#notify(datapoints:, location_name:) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/yudachi/slack_notifier.rb', line 9 def notify(datapoints:, location_name:) n = Slack::Notifier.new(@url) do defaults username: 'Yudachi' end beginning_idx = datapoints.find_index { |data| data['Type'] == 'forecast' && data['Rainfall'] >= RAINFALL_THRESHOLD } beginning = datapoints[beginning_idx] title = "#{location_name} で#{beginning["Date"].strftime("%H時%M分")}から雨が降り出しそうです!" graph = datapoints[beginning_idx..].map { |data| data['Date'].strftime('%H:%M: ') + 'x' * data['Rainfall'].ceil }.join("\n") n.ping attachments: [ { title: title, text: graph, color: 'danger' }, ] end |