Class: Ruboty::Gominohi::Notification
- Inherits:
-
Object
- Object
- Ruboty::Gominohi::Notification
- Defined in:
- lib/ruboty/gominohi/notification.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Instance Method Summary collapse
- #format(garbage_collection_day) ⇒ Object
-
#initialize(date = Date.today) ⇒ Notification
constructor
A new instance of Notification.
- #message ⇒ Object
- #search_garbage_collection_days ⇒ Object
Constructor Details
#initialize(date = Date.today) ⇒ Notification
Returns a new instance of Notification.
6 7 8 9 |
# File 'lib/ruboty/gominohi/notification.rb', line 6 def initialize(date = Date.today) @date = date @yaml = YAML.new end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/ruboty/gominohi/notification.rb', line 4 def date @date end |
Instance Method Details
#format(garbage_collection_day) ⇒ Object
41 42 43 |
# File 'lib/ruboty/gominohi/notification.rb', line 41 def format(garbage_collection_day) "#{garbage_collection_day[:emoticon]} *#{garbage_collection_day[:name]}*" end |
#message ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruboty/gominohi/notification.rb', line 20 def days = search_garbage_collection_days unless days.empty? result = days.map { |day| format(day) } str = if days.count > 1 s = result.map { |r| "- #{r}" }.join("\n") "\n#{s}\n" else " #{result.first} " end collectors = if @yaml.data[:garbage_collectors].empty? '' else @yaml.data[:garbage_collectors].map { |name| name.start_with?('@') ? name : "@#{name}" }.join(' ') + ' ' end "#{collectors}#{@date.month}月#{@date.day}日(#{@date.wday_name})のごみ収集は#{str}です。" end end |
#search_garbage_collection_days ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ruboty/gominohi/notification.rb', line 11 def search_garbage_collection_days @yaml.data[:garbage_collection_days].each_with_object([]) do |day, result| next unless day[:wday].include?(@date.wday) if !day.key?(:position) || day[:position].include?(@date.wday_position) result.push(day) end end end |