Class: Mobile::SecretSanta
- Inherits:
-
Object
- Object
- Mobile::SecretSanta
- Defined in:
- lib/mobile/secret_santa.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
Instance Method Summary collapse
-
#initialize(options) ⇒ SecretSanta
constructor
A new instance of SecretSanta.
- #pair_list ⇒ Object
- #send(options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ SecretSanta
Returns a new instance of SecretSanta.
10 11 12 13 14 15 |
# File 'lib/mobile/secret_santa.rb', line 10 def initialize() @list = [:list] @logger = [:logger] || NoopLogger.new @host_number = [:twilio_config][:host_number] @twilio_client = Twilio::REST::Client.new([:twilio_config][:account_sid], [:twilio_config][:auth_token]) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/mobile/secret_santa.rb', line 8 def logger @logger end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
8 9 10 |
# File 'lib/mobile/secret_santa.rb', line 8 def names @names end |
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
8 9 10 |
# File 'lib/mobile/secret_santa.rb', line 8 def pairs @pairs end |
Instance Method Details
#pair_list ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mobile/secret_santa.rb', line 17 def pair_list shuffled_names = names.shuffle @pairs = shuffled_names.each.with_index.reduce([]) do |pair, (person, index)| pair << { :santa => { :name => person, :number => @list[person] }, :person => shuffled_names[next_person(index)] } pair end end |
#send(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mobile/secret_santa.rb', line 30 def send( = {}) pairs = @pairs.clone pairs.each { |pair| pair[:santa][:name] = Digest::SHA256.hexdigest(pair[:santa][:name]) } @logger.info(pairs.to_json) pairs.each { |pair| @twilio_client .account . .create(payload(pair[:santa][:number], pair[:person], [:text_body])) } end |