Skip to content

Instantly share code, notes, and snippets.

@travisdmathis
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save travisdmathis/0a81f8b2312a526d2d33 to your computer and use it in GitHub Desktop.

Select an option

Save travisdmathis/0a81f8b2312a526d2d33 to your computer and use it in GitHub Desktop.
BEGIN
(0.1ms) ROLLBACK
=> #<MonthlyStat id: nil, client_id: 23, stat_type: "StorageTotal", month: "June", year: 2014, value: 106862824740, created_at: nil, updated_at: nil>
class MonthlyStat < ActiveRecord::Base
belongs_to :client
attr_accessible :client_id, :month, :stat_type, :value, :year
accepts_nested_attributes_for :client
classy_enum_attr :stat_type, enum: 'MonthlyStatType'
class << self
def storage_total(client)
@date = Date.today
@month = @date.strftime("%B")
@year = @date.strftime("%Y")
@client = client
@value = @client.current_storage_total
puts "Date: #{@month} #{@year} - Client: #{@client} - Value: #{@value} - Client ID: #{@client.id}"
MonthlyStat.create(client_id: @client.id, month: @month, value: @value, year: @year, stat_type: :StorageTotal )
end
def bandwidth_usage(client)
@date = Date.today
@month = @date.strftime("%B")
@year = @date.strftime("%Y")
@client = client
@value = @client.bandwidth_usage
puts "Date: #{@month} #{@year} - Client: #{@client} - Value: #{@value} - Client ID: #{@client.id}"
MonthlyStat.create(client_id: @client.id, month: @month, value: @value, year: @year, stat_type: :BandwidthUsage )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment