File: filter.rb

package info (click to toggle)
ruby-cliver 0.3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 208 kB
  • sloc: ruby: 760; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# encoding: utf-8

module Cliver
  # A Namespace to hold filter procs
  module Filter
    # The identity filter returns its input unchanged.
    IDENTITY = proc { |version| version }

    # Apply to a list of requirements
    # @param requirements [Array<String>]
    # @return [Array<String>]
    def requirements(requirements)
      requirements.map do |requirement|
        req_parts = requirement.split(/\b(?=\d)/, 2)
        version = req_parts.last
        version.replace apply(version)
        req_parts.join
      end
    end

    # Apply to some input
    # @param version [String]
    # @return [String]
    def apply(version)
      to_proc.call(version)
    end
  end
end