Class: CelluloidPubsub::GemVersionParser
- Inherits:
-
Object
- Object
- CelluloidPubsub::GemVersionParser
- Defined in:
- lib/celluloid_pubsub/gem_version_parser.rb
Overview
class used for parsing gem versions
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
The additional options for parsing the version.
-
#version ⇒ String, Integer
readonly
Version that needs parsing.
Instance Method Summary collapse
-
#initialize(version, options = {}) ⇒ void
constructor
receives the version and the additional options.
-
#number_with_single_decimal_point ⇒ void
pops from the version array elements until its size is 2.
-
#parsed_number ⇒ Float
parses the version and returns the version with a single decimal point by default.
Constructor Details
#initialize(version, options = {}) ⇒ void
receives the version and the additional options
:nocov:
23 24 25 26 |
# File 'lib/celluloid_pubsub/gem_version_parser.rb', line 23 def initialize(version, = {}) @version = version @options = .is_a?(Hash) ? : {} end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns 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, = {}) @version = version @options = .is_a?(Hash) ? : {} 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 |
#version ⇒ String, Integer (readonly)
Returns 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, = {}) @version = version @options = .is_a?(Hash) ? : {} 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_point ⇒ void
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_number ⇒ Float
parses the version and returns the version with a single decimal point by default
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 |