Sha256: 8de34fa928fac18260e9dc469a84a655346b03674b2d676c26325be7bbc9f58a

Contents?: true

Size: 1.03 KB

Versions: 31

Compression:

Stored size: 1.03 KB

Contents

require 'skylight/messages/base'

module Skylight
  module Messages
    class Hello < Base

      DIGITS = /^\s*\d+\s*$/

      required :version, :string, 1
      optional :config,  :uint32, 2
      repeated :cmd,     :string, 3

      def newer?(other = VERSION)
        other = split(other)
        curr  = split(version)

        [other.length, curr.length].max.times do |i|
          next if other[i] == curr[i]
          return true unless other[i]

          if other[i] =~ DIGITS
            if curr[i] =~ DIGITS
              other_i = other[i].to_i
              curr_i = curr[i].to_i

              next if other_i == curr_i

              return curr_i > other_i
            else
              return false
            end
          else
            if curr[i] =~ DIGITS
              return true
            else
              next if curr[i] == other[i]
              return curr[i] > other[i]
            end
          end
        end

        false
      end

    private

      def split(v)
        v.split('.')
      end

    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
skylight-0.2.7 lib/skylight/messages/hello.rb
skylight-0.2.6 lib/skylight/messages/hello.rb
skylight-0.2.5 lib/skylight/messages/hello.rb
skylight-0.2.4 lib/skylight/messages/hello.rb
skylight-0.2.3 lib/skylight/messages/hello.rb
skylight-0.2.2 lib/skylight/messages/hello.rb
skylight-0.2.1 lib/skylight/messages/hello.rb
skylight-0.2.0 lib/skylight/messages/hello.rb
skylight-0.2.0.beta.4 lib/skylight/messages/hello.rb
skylight-0.2.0.beta.3 lib/skylight/messages/hello.rb
skylight-0.2.0.beta.2 lib/skylight/messages/hello.rb
skylight-0.2.0.beta.1 lib/skylight/messages/hello.rb
skylight-0.1.8 lib/skylight/messages/hello.rb
skylight-0.1.7 lib/skylight/messages/hello.rb
skylight-0.1.7.alpha1 lib/skylight/messages/hello.rb
skylight-0.1.6 lib/skylight/messages/hello.rb
skylight-0.1.6.alpha3 lib/skylight/messages/hello.rb
skylight-0.1.6.alpha1 lib/skylight/messages/hello.rb
skylight-0.1.5 lib/skylight/messages/hello.rb
skylight-0.1.5.alpha2 lib/skylight/messages/hello.rb