Module: Trello::Helpers
- Included in:
- Main
- Defined in:
- lib/trello/helpers.rb
Instance Method Summary collapse
- #format_api_url(url) ⇒ Object
- #prompt_for_list_from_options(prompt_message) ⇒ Object
- #prompt_from_options(prompt_message) ⇒ Object
- #root ⇒ Object
- #user_check ⇒ Object
- #write_json_to_file(hash, filename) ⇒ Object
Instance Method Details
#format_api_url(url) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/trello/helpers.rb', line 7 def format_api_url(url) url = 'http://' + url unless url.start_with?('http://') url += '/' unless url.end_with?('/') begin # ensure it's a valid url before returning URI.parse(url).to_s rescue abort "#{url} is not a valid URL." end end |
#prompt_for_list_from_options(prompt_message) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trello/helpers.rb', line 22 def () var = nil = yield .each_with_index do |opt, i| puts "#{i}: #{opt[:name]}" end until var response = ask().split(',').map(&:to_i) if response.all?{|id| id && [id] } var = .values_at(*response).map{|option| option[:id]} else = response.select{|id| !(id && [id])} puts "Invalid options #{.join(', ')}. Please give numbers between 0 and #{.length} separated by commas." end end var end |
#prompt_from_options(prompt_message) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trello/helpers.rb', line 41 def () var = nil = yield .each_with_index do |opt, i| puts "#{i}: #{opt[:name]}" end until var response = to_i(ask()) if response && [response] var = [response][:id] else say "Invalid option - please give a number between 0 and #{.length}." end end var end |
#root ⇒ Object
3 4 5 |
# File 'lib/trello/helpers.rb', line 3 def root File.dirname __dir__ end |
#user_check ⇒ Object
18 19 20 |
# File 'lib/trello/helpers.rb', line 18 def user_check param_check('user', "No user defined! Specify a user with trello config --user <username>.") end |
#write_json_to_file(hash, filename) ⇒ Object
59 60 61 62 |
# File 'lib/trello/helpers.rb', line 59 def write_json_to_file(hash, filename) puts hash File.open(filename, 'w') {|f| f.write JSON.pretty_generate(hash)} end |