halogenandtoast/timelord · matcher_loader.rb
ruby logo
def sort_matchers(matchers)
      matchers.sort { |a, b| b::REGEX.to_s.length <=> a::REGEX.to_s.length }
    end
Similar code snippets
1.
nning/transmission-rss · feed.rb
Match rating: 59.15% · See similar code snippets
ruby logo
def build_regexp(matchers)
      matchers = Array(matchers).map { |m| to_regexp(m) }
      matchers.empty? ? nil : Regexp.union(matchers)
    end
2.
halogenandtoast/timelord · matcher_loader.rb
Match rating: 58.83% · See similar code snippets
ruby logo
def load_all
      matchers = files.map { |file| get_class(file) }
      sort_matchers(matchers) + [NoMatcher]
    end
3.
mashiro/kashiwamochi · query.rb
Match rating: 50.96% · See similar code snippets
ruby logo
def to_option(*sort_keys)
      sort_keys = sort_keys.flatten.map(&:to_s).uniq
      sorts = @sort_params.values
      sorts.reject! { |s| !sort_keys.include?(s.key.to_s) } unless sort_keys.empty?

      hash = Hash[@search_params.values.map { |search| [search.key, search.value] }]
      unless sorts.empty?
        hash[Kashiwamochi.config.sort_key] = case sorts.length
                                             when 1 then sorts.first.to_query
                                             else        sorts.map(&:to_query)
                                             end
      end
      hash
    end
4.
wvanbergen/request-log-analyzer · numeric_value.rb
Match rating: 50.18% · See similar code snippets
ruby logo
def sorted_by(by = nil)
      if block_given?
        categories.sort { |a, b| yield(b[1]) <=> yield(a[1]) }
      else
        categories.sort { |a, b| send(by, b[0]) <=> send(by, a[0]) }
      end
    end
5.
deansc/wp_roster · roster.rb
Match rating: 49.97% · See similar code snippets
ruby logo
def order field, sort      
      sort == :asc ? self.sort { |a,b| a.send(field) <=> b.send(field) } : self.sort { |a,b| b.send(field) <=> a.send(field) }
    end
6.
webzakimbo/bcome-kontrol · base.rb
Match rating: 49.92% · See similar code snippets
ruby logo
def has_key_and_value?(matchers)
      matchers[:values] = [matchers[:values]] if matchers[:values] && !matchers[:values].is_a?(Array)

      raise Bcome::Exception::InvalidMatcherQuery unless matchers[:key] && matchers[:values].is_a?(Array)
      key = matchers[:key].to_sym
      values = matchers[:values]
      @data.key?(key) && values.include?(@data[key])
    end
7.
redding/deas · runner.rb
Match rating: 49.75% · See similar code snippets
ruby logo
def sorted_param_names
      # Sort longer key names first so they will be processed first.  This
      # ensures that shorter param names that compose longer param names won't
      # be subbed in the longer param name's place.
      self.params.keys.sort{ |a, b| b.size <=> a.size }
    end
8.
nalbeza/roaster · query.rb
Match rating: 49.49% · See similar code snippets
ruby logo
def parse_sort_criteria(criteria)
      sorting_parameters = {}
      criteria.to_s.split(',').each do |sort_value|
        sort_order = sort_value[0] == '-' ? :desc : :asc
        sort_value = sort_value.gsub(/\A\-/, '').downcase.to_sym
        sorting_parameters[sort_value] = sort_order
      end
      sorting_parameters
    end
9.
paxtonhare/marklogic-ruby-driver · cursor.rb
Match rating: 49.08% · See similar code snippets
ruby logo
def sort
      return nil unless has_sort?

      sorters = @options[:sort] || @options[:order]
      sorters = [sorters] unless sorters.instance_of?(Array)

      sorters.map do |sorter|
        name = sorter[0].to_s
        direction = (sorter[1] && (sorter[1] == -1)) ? "descending" : "ascending"


        if @collection.database.has_range_index?(name)
          index = @collection.database.range_index(name)
          type = %Q{xs:#{index.scalar_type}}
          collation = index.collation
        else
          raise MissingIndexError.new("Missing index on #{name}")
        end
        {
          "direction" => direction || "ascending",
          "type" => type,
          "collation" => collation || "",
          "json-property" => name
        }
      end
    end
10.
lambda2/rice_cooker · helpers.rb
Match rating: 48.87% · See similar code snippets
ruby logo
def parse_sorting_param(sorting_param, model)
      return {} unless sorting_param.present?

      sorting_params = CSV.parse_line(URI.unescape(sorting_param)).collect do |sort|
        sorting_param = if sort.start_with?('-')
                          { field: sort[1..-1].to_s.to_sym, direction: :desc }
                        else
                          { field: sort.to_s.to_sym, direction: :asc }
                        end

        check_sorting_param(model, sorting_param)
        sorting_param
      end
      sorting_params.map { |par| [par[:field], par[:direction]] }.to_h
    end