-
-
Save jfarmer/5417613 to your computer and use it in GitHub Desktop.
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
# Slightly better name, bang (!) to indicate side effects | |
def process_raw_data! | |
# See: | |
# http://po-ru.com/diary/rubys-magic-underscore/ | |
# http://po-ru.com/diary/destructuring-assignment-in-ruby/ | |
self.raw_data.each do |date, name, url, cb_url, funding_type, value| | |
Company.where(name: name).first_or_create(url: url, cb_url: cb_url) | |
# See: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-strptime | |
Event.where(funding_type: funding_type, date: Date.strptime(date, '%M/%y'), value: value).first_or_create | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Re: my comment on Facebook, something like this (danger: this is oogly, funny indentation only to prevent line wraps in this comment)
You could in principle do
due to how
==
works onActiveRecord::Relation
objects, but I don't know a clean way to then get at the URL and callback URLs. You'd either have to attach the data in thegroup_by
key somehow without generating a query, or probe the first entry in the array that's now the value for a particular key.