Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Created May 29, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdammkoehler/0d993b5d6c50b955aada to your computer and use it in GitHub Desktop.
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
#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