Last active
December 23, 2015 09:28
-
-
Save StephenOTT/6614278 to your computer and use it in GitHub Desktop.
Sample of groupdate question
Causing formatting changes
Comment out require 'groupdate' to see different in terminal output
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 'date' | |
require 'groupdate' | |
class DateManipulate | |
def initialize | |
@creationDateCount = [{"_id"=>{"year"=>2012, "month"=>10}, "number"=>53}, {"_id"=>{"year"=>2012, "month"=>12}, "number"=>58}, {"_id"=>{"year"=>2011, "month"=>8}, "number"=>8}, {"_id"=>{"year"=>2012, "month"=>11}, "number"=>75}, {"_id"=>{"year"=>2011, "month"=>9}, "number"=>58}, {"_id"=>{"year"=>2013, "month"=>9}, "number"=>67}, {"_id"=>{"year"=>2013, "month"=>6}, "number"=>561}, {"_id"=>{"year"=>2012, "month"=>9}, "number"=>102}, {"_id"=>{"year"=>2013, "month"=>5}, "number"=>609}, {"_id"=>{"year"=>2012, "month"=>7}, "number"=>84}, {"_id"=>{"year"=>2010, "month"=>12}, "number"=>1}, {"_id"=>{"year"=>2013, "month"=>7}, "number"=>595}, {"_id"=>{"year"=>2013, "month"=>3}, "number"=>253}, {"_id"=>{"year"=>2012, "month"=>6}, "number"=>129}, {"_id"=>{"year"=>2012, "month"=>2}, "number"=>95}, {"_id"=>{"year"=>2012, "month"=>4}, "number"=>50}, {"_id"=>{"year"=>2013, "month"=>8}, "number"=>736}, {"_id"=>{"year"=>2013, "month"=>1}, "number"=>242}, {"_id"=>{"year"=>2011, "month"=>11}, "number"=>46}, {"_id"=>{"year"=>2012, "month"=>3}, "number"=>68}, {"_id"=>{"year"=>2011, "month"=>10}, "number"=>48}, {"_id"=>{"year"=>2012, "month"=>1}, "number"=>70}, {"_id"=>{"year"=>2012, "month"=>8}, "number"=>70}, {"_id"=>{"year"=>2013, "month"=>2}, "number"=>266}, {"_id"=>{"year"=>2011, "month"=>12}, "number"=>47}, {"_id"=>{"year"=>2013, "month"=>4}, "number"=>449}, {"_id"=>{"year"=>2012, "month"=>5}, "number"=>77}] | |
puts self.sortHash | |
end | |
def sortHash () | |
dateFormatChangeHash = {} | |
@creationDateCount.each do |x| | |
temp = Date.strptime(x["_id"].values_at('month', 'year').join(" "), '%m %Y') | |
dateFormatChangeHash[temp] = x["number"] | |
end | |
sortedDates = dateFormatChangeHash.keys.sort | |
#puts sortedDates | |
sortedHash = {} | |
sortedDates.each do |y| | |
sortedHash[y] = dateFormatChangeHash[y] | |
end | |
return sortedHash | |
end | |
end | |
start = DateManipulate.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment