Class: GithubSearch::SearchStringBuilder
- Inherits:
-
Object
- Object
- GithubSearch::SearchStringBuilder
- Defined in:
- lib/github-search/search_string_builder.rb
Instance Method Summary collapse
- #args_untangler(args) ⇒ Object
- #build_search_string(args, opts, model) ⇒ Object
- #opts_untangler(opts, model) ⇒ Object
- #order_untangler(order_param) ⇒ Object
- #sort_untangler(sort_param, model) ⇒ Object
Instance Method Details
#args_untangler(args) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/github-search/search_string_builder.rb', line 17 def args_untangler(args) search_params = "?q=" plus = "" args.each do |search_term| search_params += "#{plus}#{search_term}" plus = "+" end search_params end |
#build_search_string(args, opts, model) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/github-search/search_string_builder.rb', line 7 def build_search_string(args, opts, model) args_string = args_untangler(args) opts_string = opts_untangler(opts, model) search_string = args_string search_string += "+" if opts_string search_string += opts_string end |
#opts_untangler(opts, model) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/github-search/search_string_builder.rb', line 27 def opts_untangler(opts, model) sort_string = sort_untangler(opts[:sort], model) if opts[:sort] opts.delete(:sort) order_string = order_untangler(opts[:order]) if opts[:order] opts.delete(:order) search_params = "" plus = "" opts.each do |key, value| search_params += "#{plus}#{key}:#{value}" plus = "+" end search_params += sort_string || "" search_params += order_string || "" end |
#order_untangler(order_param) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/github-search/search_string_builder.rb', line 53 def order_untangler(order_param) if [:asc, :desc].include?(order_param) order_string = "&order=#{order_param.to_s}" else # todo: error handling puts "You can only order repositories with :asc or :desc (default is desc)" end end |
#sort_untangler(sort_param, model) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/github-search/search_string_builder.rb', line 44 def sort_untangler(sort_param, model) if model..include?(sort_param) sort_string = "&sort=#{sort_param.to_s}" else # todo: error handling puts "You can only sort a #{model} for #{model.}. (default is best match)" end end |