Created
May 29, 2014 15:50
-
-
Save rdammkoehler/0d993b5d6c50b955aada to your computer and use it in GitHub Desktop.
There must be a better way to do this. The cards(...) method is kinda ugly as is lists_in(...) But for the life of me I cannot see a way to make it prettier
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
#where the json content is a trello board that has been sucked into jsoncontent | |
def lists_in(jsoncontent) | |
lists = jsoncontent['lists'] | |
[Hash[ lists.collect { |list| [ list['id'], list['name'] ] } ], lists.map { |list| list['id'] if list['closed'] }.to_set] | |
end | |
def id_for(card) | |
card['idList'] | |
end | |
def closed?(card) | |
card['closed'] | |
end | |
# [], open cards on open lists | |
def cards(jsoncontent) | |
list_id_hash, closed_list_ids = lists_in jsoncontent | |
jsoncontent['cards'].select { |card| | |
((! closed?(card)) && (! closed_list_ids.include? id_for(card))) | |
}.each { |card| | |
card['list_name'] = list_id_hash[ id_for(card) ] | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment