This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.count_vhs_by_rentals | |
Rental.all.each_with_object({}) do |rental, vhs_hash| | |
vhs_hash[rental.vhs].nil? ? vhs_hash[rental.vhs] = 1 : vhs_hash[rental.vhs] += 1 | |
end | |
end | |
#=> {<Vhs:0x00007f8d5e2bf0f0 id: 17, serial_number: "MAX-luqovgdk8e7tl", movie_id: 9 => 1, | |
#<Vhs:0x00007f8d4f81a4a0 id: 29, serial_number: "BABA-t6k24krzqclts", movie_id: 13 =>2, | |
#<Vhs:0x00007f8d4f854538 id: 11, serial_number: "BABA-begvxe7ai0rc6", movie_id: 13 =>3} | |
def self.count_vhs_by_client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
“hello”.capitalize #=> “Hello” | |
“hello”.send(“capitalize”) #=> “Hello” |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.count_vhs_rentals_by(attribute) | |
Rental.all.each_with_object({}) do |rental, vhs_hash| | |
vhs_hash[rental.send(“#{attribute}”)].nil? ? vhs_hash[rental.“#{attribute}”] = 1 : vhs_hash[rental.“#{attribute}”] += 1 | |
end | |
end | |
Vhs.count_vhs_rentals_by(“vhs”) #=> | |
#{<Vhs:0x00007f8d5e2bf0f0 id: 17, serial_number: "MAX-luqovgdk8e7tl", movie_id: 9 => 1, | |
#<Vhs:0x00007f8d4f81a4a0 id: 29, serial_number: "BABA-t6k24krzqclts", movie_id: 13 =>2, | |
#<Vhs:0x00007f8d4f854538 id: 11, serial_number: "BABA-begvxe7ai0rc6", movie_id: 13 =>3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GenericHelpers | |
def make_hash_by_attribute(array, attribute) | |
array.each_with_object({}) do |array_item, new_hash| | |
new_hash[array_item.send("#{attribute}")].nil? ? new_hash[array_item.send("#{attribute}")] = 1 : new_hash[array_item.send("#{attribute}")] += 1 | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Vhs | |
include GenericHelpers | |
extend GenericHelpers | |
def self.count_vhs_by_rentals | |
make_hash_by_attribute(Rental.all, "vhs") | |
end | |
def self.count_vhs_by_client | |
make_hash_by_attribute(Rental.all, "client") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Client | |
include GenericHelpers | |
extend GenericHelpers | |
def self.count_clients_by_age | |
make_hash_by_attribute(Client.all, "age") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rental.group(:vhs).count #=> | |
#{<Vhs:0x00007f8d5e2bf0f0 id: 17, serial_number: "MAX-luqovgdk8e7tl", movie_id: 9 => 1, | |
#<Vhs:0x00007f8d4f81a4a0 id: 29, serial_number: "BABA-t6k24krzqclts", movie_id: 13 =>2, | |
#<Vhs:0x00007f8d4f854538 id: 11, serial_number: "BABA-begvxe7ai0rc6", movie_id: 13 =>3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twilio-ruby' | |
account_sid = 'ACcd207c4be71151a3f50ef05c79e865d5' | |
auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyy' | |
client = Twilio::REST::Client.new(account_sid, auth_token) | |
from = '+15551234567' # Your Twilio number | |
to = '+15555555555' # The mobile number the text will be sent to | |
client.messages.create( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dotenv/load' #This ruby gem will is what we will be using to secure our Twilio credentials | |
require 'twilio-ruby' | |
module TwilioControls | |
# To set up environmental variables, see http://twil.io/secure | |
@@account_sid = ENV['TWILIO_ACCOUNT_SID'] #This is used in conjuction with the 'dotenv/load' gem | |
@@auth_token = ENV['TWILIO_AUTH_TOKEN'] #This is used in conjuction with the 'dotenv/load' gem | |
@@client = Twilio::REST::Client.new(@@account_sid, @@auth_token) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export TWILIO_ACCOUNT_SID='AC###################################' | |
export TWILIO_AUTH_TOKEN='################################' | |
#your account_sid and auth_token can be found on your Twilio console at twilio.com/console |
OlderNewer