Class: Twilio::Rails::Phone::Tree::MessageSet
- Inherits:
-
Object
- Object
- Twilio::Rails::Phone::Tree::MessageSet
- Includes:
- Enumerable
- Defined in:
- lib/twilio/rails/phone/tree.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #first ⇒ Object
-
#initialize(set) ⇒ MessageSet
constructor
A new instance of MessageSet.
- #last ⇒ Object
- #length ⇒ Object
Constructor Details
#initialize(set) ⇒ MessageSet
Returns a new instance of MessageSet.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/twilio/rails/phone/tree.rb', line 177 def initialize(set) @messages = [] # This whole chunk here feels like an incorrect level of abstraction. That it should be the caller's responsbiility # to pass in the contents of `message:` and not a hash with `message:` as a key. But maybe it's ok to do it once # here so the callsites can be cleaner passthroughs without doing the checks over and over. if set.is_a?(Hash) set = set.symbolize_keys if set.key?(:message) raise Twilio::Rails::Phone::InvalidTreeError, "MessageSet should never receive a hash with any key other than :message but received #{ set }" if set.keys != [:message] set = set[:message] end end set = [set] unless set.is_a?(Array) set.each do || next nil if .blank? if .is_a?(Twilio::Rails::Phone::Tree::Message) @messages << elsif .is_a?(Proc) @messages << elsif .is_a?(String) @messages << Twilio::Rails::Phone::Tree::Message.new(say: ) elsif .is_a?(Hash) @messages << Twilio::Rails::Phone::Tree::Message.new(**.symbolize_keys) else raise Twilio::Rails::Phone::InvalidTreeError, "message value #{ } is not valid" end end end |
Instance Method Details
#each(&block) ⇒ Object
209 210 211 |
# File 'lib/twilio/rails/phone/tree.rb', line 209 def each(&block) @messages.each(&block) end |
#first ⇒ Object
217 218 219 |
# File 'lib/twilio/rails/phone/tree.rb', line 217 def first @messages.first end |
#last ⇒ Object
221 222 223 |
# File 'lib/twilio/rails/phone/tree.rb', line 221 def last @messages.last end |
#length ⇒ Object
213 214 215 |
# File 'lib/twilio/rails/phone/tree.rb', line 213 def length @messages.count end |