Class: Doc::Configurator::Ruby::VersionSpecifier
- Inherits:
-
Object
- Object
- Doc::Configurator::Ruby::VersionSpecifier
- Includes:
- Comparable
- Defined in:
- lib/doc/configurator/ruby/version_specifier.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#str ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute str.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #===(other) ⇒ Object
- #dir_name ⇒ Object
- #drop ⇒ Object
- #full_version? ⇒ Boolean
-
#initialize(o) ⇒ VersionSpecifier
constructor
A new instance of VersionSpecifier.
- #valid? ⇒ Boolean
Constructor Details
#initialize(o) ⇒ VersionSpecifier
Returns a new instance of VersionSpecifier.
7 8 9 10 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 7 def initialize(o) @str = o.to_s @parts = str.scan(/\d+/).map(&:to_i) end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
5 6 7 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 5 def parts @parts end |
#str ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute str.
5 6 7 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 5 def str @str end |
Instance Method Details
#<=>(other) ⇒ Object
30 31 32 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 30 def <=>(other) parts <=> other.parts end |
#===(other) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 34 def ===(other) if other.respond_to?(:parts) parts == other.parts[0, parts.length] else str === other end end |
#dir_name ⇒ Object
24 25 26 27 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 24 def dir_name fmt = 'ruby' + %w[-%d .%d .%d -p%d].take(parts.length).join('') fmt % parts end |
#drop ⇒ Object
12 13 14 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 12 def drop self.class.new(parts.drop(1).join('.')) end |
#full_version? ⇒ Boolean
20 21 22 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 20 def full_version? valid? && parts.length == 4 end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/doc/configurator/ruby/version_specifier.rb', line 16 def valid? str =~ /^\d+\.\d+(?:\.\d+(?:-p\d+)?)?$/ end |