Class: FluentCommandBuilder::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent_command_builder/internal/version.rb

Constant Summary collapse

VERSION_REGEX =
'(?:\d+\.)+(?:\d+)'
DELIMITER =
'.'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



9
10
11
12
# File 'lib/fluent_command_builder/internal/version.rb', line 9

def initialize(version)
  raise "#{version} is not a valid version." unless Version.is_valid? version
  @version = version
end

Instance Attribute Details

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/fluent_command_builder/internal/version.rb', line 7

def version
  @version
end

Class Method Details

.match(value) ⇒ Object



30
31
32
33
34
35
# File 'lib/fluent_command_builder/internal/version.rb', line 30

def self.match(value)
  exp = Regexp.new VERSION_REGEX
  version = value.scan(exp)[0]
  return unless version
  Version.new(version)
end

Instance Method Details

#compactObject



14
15
16
# File 'lib/fluent_command_builder/internal/version.rb', line 14

def compact
  first 2, ''
end

#first(count, delimiter = DELIMITER) ⇒ Object



18
19
20
# File 'lib/fluent_command_builder/internal/version.rb', line 18

def first(count, delimiter=DELIMITER)
  to_a.first(count).join(delimiter)
end

#to_aObject



26
27
28
# File 'lib/fluent_command_builder/internal/version.rb', line 26

def to_a
  @version.split DELIMITER
end

#to_sObject



22
23
24
# File 'lib/fluent_command_builder/internal/version.rb', line 22

def to_s
  @version
end