Paludis Logo Introduction Examples
Bugs, Requests, Support C++ (core)
Overview Ruby (bindings)
FAQ Python (bindings)
Clients  
Configuration  
API  

example_version_operator.rb

This example demonstrates how use Paludis::version_spec_comparator.

00001 #!/usr/bin/env ruby
00002 # vim: set sw=4 sts=4 et tw=100 :
00003 
00004 =begin description
00005 This example demonstrates how use Paludis::version_spec_comparator.
00006 =end
00007 
00008 require 'Paludis'
00009 require 'example_command_line'
00010 
00011 include Paludis
00012 
00013 #Make an array of Versions
00014 versions = [VersionSpec.new('1.0'), VersionSpec.new('1.1'), VersionSpec.new('1.2'),
00015     VersionSpec.new('1.2-r1'), VersionSpec.new('2.0')]
00016 
00017 #Make an array of VersionOperator strings
00018 operators = ['=', '>=', '~', '<', '~>']
00019 
00020 # Display a header
00021 print " #{'LHS'.ljust(8)} | #{'RHS'.ljust(8)}"
00022 operators.each do |operator|
00023     print " | #{operator.ljust(8)}"
00024 end
00025 
00026 puts
00027 
00028 print '-' * 10
00029 puts ('+' + ('-' * 10)) * operators.length.succ
00030 
00031 #For each pair of versions
00032 versions.each do |v1|
00033     versions.each do |v2|
00034         print " #{v1.to_s.ljust(8)} | #{v2.to_s.ljust(8)}"
00035 
00036         #Apply all of our operators, and show the results
00037         operators.each do |operator|
00038             print " | " + (Paludis::version_spec_comparator(operator, v1, v2) ? 'true' : 'false').ljust(8)
00039         end
00040         puts
00041     end
00042 end