Class: BasicVersion
Direct Known Subclasses
Constant Summary collapse
- Fields =
:major, :minor, :tiny
- GlobString =
(['*'] * Fields.size).join('.')
- StringRexp =
/#{(['(\d+)'] * Fields.size).join('\.')}/
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(*args) ⇒ BasicVersion
constructor
A new instance of BasicVersion.
- #succ ⇒ Object
- #to_a ⇒ Object
- #to_ruby_code(module_name = 'AppVersion', namespace_type = 'module') ⇒ Object
- #to_ruby_constants ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ BasicVersion
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/basic_version.rb', line 7 def initialize(*args) if args.size == 1 && args.first.kind_of?(String) && md = StringRexp.match(args.first) args = md.captures.map { |a| a.to_i } end case args.size when 0 # no-op when 1 self.tiny = args.first.to_i when 3 self.major, self.minor, self.tiny = *args.map{|a| a.to_i } else raise ArgumentError end Fields.each_with_index do |f, i| next unless self.send(f).nil? self.send(:"#{f}=", 0) end end |
Instance Method Details
#<=>(other) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/basic_version.rb', line 61 def <=>(other) v = 0 Fields.each do |f| return v unless other.respond_to?(f) v = self.send(f) <=> other.send(f) return v unless v == 0 end v end |
#succ ⇒ Object
57 58 59 |
# File 'lib/basic_version.rb', line 57 def succ self.class.new(self.major, self.minor, self.tiny + 1) end |
#to_a ⇒ Object
27 28 29 |
# File 'lib/basic_version.rb', line 27 def to_a [self.major, self.minor, self.tiny] end |
#to_ruby_code(module_name = 'AppVersion', namespace_type = 'module') ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/basic_version.rb', line 44 def to_ruby_code(module_name = 'AppVersion', namespace_type = 'module') <<-EORUBY #{namespace_type} #{module_name} module VERSION #{to_ruby_constants.strip} self end end EORUBY end |
#to_ruby_constants ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/basic_version.rb', line 35 def to_ruby_constants <<-EORUBY MAJOR = #{self.major} MINOR = #{self.minor} TINY = #{self.tiny} STRING = #{to_s.inspect} EORUBY end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/basic_version.rb', line 31 def to_s "%d.%d.%d" % to_a end |