Class: CelluloidPubsub::GemVersionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/celluloid_pubsub/gem_version_parser.rb

Overview

class used for parsing gem versions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, options = {}) ⇒ void

receives the version and the additional options

:nocov:

Parameters:

  • version (String, Integer)

    the version that needs parsing

  • options (Hash) (defaults to: {})

    The additional options for parsing the version



23
24
25
26
# File 'lib/celluloid_pubsub/gem_version_parser.rb', line 23

def initialize(version, options = {})
  @version = version
  @options = options.is_a?(Hash) ? options : {}
end

Instance Attribute Details

#optionsHash (readonly)

Returns The additional options for parsing the version.

Returns:

  • (Hash)

    The additional options for parsing the version



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/celluloid_pubsub/gem_version_parser.rb', line 10

class GemVersionParser
  attr_reader :version, :options

  #  receives the version and the additional options
  #
  # @param  [String, Integer] version  the version that needs parsing
  # @param [Hash] options The additional options for parsing the version
  #
  # @return [void]
  #
  # @api public
  #
  # :nocov:
  def initialize(version, options = {})
    @version = version
    @options = options.is_a?(Hash) ? options : {}
  end

  #  parses the version and returns the version with a single decimal point by default
  # @return [Float]
  #
  # @api public
  def parsed_number
    return 0 if @version.blank?
    @version_array = @version.to_s.split('.')
    number_with_single_decimal_point if @version_array.size > 2
    @version_array.join('.').to_f
  end

  # pops from the version array elements until its size is 2
  # @return [void]
  #
  # @api public
  def number_with_single_decimal_point
    @version_array.pop until @version_array.size == 2
  end
end

#versionString, Integer (readonly)

Returns version that needs parsing.

Returns:

  • (String, Integer)

    version that needs parsing



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/celluloid_pubsub/gem_version_parser.rb', line 10

class GemVersionParser
  attr_reader :version, :options

  #  receives the version and the additional options
  #
  # @param  [String, Integer] version  the version that needs parsing
  # @param [Hash] options The additional options for parsing the version
  #
  # @return [void]
  #
  # @api public
  #
  # :nocov:
  def initialize(version, options = {})
    @version = version
    @options = options.is_a?(Hash) ? options : {}
  end

  #  parses the version and returns the version with a single decimal point by default
  # @return [Float]
  #
  # @api public
  def parsed_number
    return 0 if @version.blank?
    @version_array = @version.to_s.split('.')
    number_with_single_decimal_point if @version_array.size > 2
    @version_array.join('.').to_f
  end

  # pops from the version array elements until its size is 2
  # @return [void]
  #
  # @api public
  def number_with_single_decimal_point
    @version_array.pop until @version_array.size == 2
  end
end

Instance Method Details

#number_with_single_decimal_pointvoid

This method returns an undefined value.

pops from the version array elements until its size is 2



43
44
45
# File 'lib/celluloid_pubsub/gem_version_parser.rb', line 43

def number_with_single_decimal_point
  @version_array.pop until @version_array.size == 2
end

#parsed_numberFloat

parses the version and returns the version with a single decimal point by default

Returns:

  • (Float)


32
33
34
35
36
37
# File 'lib/celluloid_pubsub/gem_version_parser.rb', line 32

def parsed_number
  return 0 if @version.blank?
  @version_array = @version.to_s.split('.')
  number_with_single_decimal_point if @version_array.size > 2
  @version_array.join('.').to_f
end