This file contains 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 'rubygems' | |
require 'sequel' | |
require 'csv' | |
def parse_data(file_name) | |
CSV.read(file_name, headers: :first_row).to_a | |
end | |
db = Sequel.sqlite |
This file contains 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
Merchant Date Ends Deal Price Value | |
Burger King 10/2/2011 10/4/2011 Your way 25 50 | |
McDonalds 10/5/2011 Not really food 22 44 | |
Arbys 10/8/2011 10/10/2011 More burgers 7 14 |
This file contains 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
Merchant Date Ends Deal Price Value | |
Burger King 10/2/2011 10/4/2011 Your way 25 50 | |
McDonalds 10/5/2011 Not really food 22 44 | |
Arbys 10/8/2011 10/10/2011 More burgers 7 14 |
This file contains 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 Cloning | |
def clone_record(column: :name) | |
self.class.create(column => cloned_column_attribute(column)) | |
end | |
private | |
def cloned_column_attribute(column) | |
1.upto(Float::INFINITY) do |clone_number| | |
column_attribute = public_send(column) |
This file contains 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 AppCache | |
def initialize | |
@store = Store.new | |
end | |
def cache(*keys, &block) | |
options = keys.extract_options! | |
@store.cache(keys, options[:expires_in], &block) | |
end |
This file contains 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
1.upto(100) do |i| | |
puts ''.tap {|output| | |
output << 'Fizz' if i.modulo(3).zero? | |
output << 'Buzz' if i.modulo(5).zero? | |
output << i.to_s if output.empty? | |
} | |
end |
This file contains 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 SyncToAnalyticsService | |
ConnectionFailure = Class.new(StandardError) | |
def self.perform(data) | |
new(data).perform | |
end | |
def initialize(data) | |
@data = data.symbolize_keys | |
@account = Account.find(@data[:account_id]) |
This file contains 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 SyncToAnalyticsService | |
ConnectionFailure = Class.new(StandardError) | |
def self.perform(data) | |
new(data).perform | |
end | |
def initialize(data) | |
@data = data.symbolize_keys | |
@account = Account.find(@data[:account_id]) |
This file contains 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
describe |
This file contains 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 Post | |
FetchError = Class.new(StandardError) | |
def self.able_to_fetch? | |
# https://github.com/djberg96/net-ping | |
# `ping?` determines its boolean by rescuing an exception (SocketError). | |
# Where that exception is handled is up to you. Do you want it to occur in | |
# a gem (net-ping) or in your controller? Either way, doesn't fucking matter, | |
# someone's gotta do it. | |
Net::Ping::HTTP.new(service_url).ping? |