Sha256: 514d2028a278ffc51738999d1b8fe93e476d27789be81cf92f1d575f747f59d1

Contents?: true

Size: 630 Bytes

Versions: 3

Compression:

Stored size: 630 Bytes

Contents

module UserAgentParser
  
  class Version

    attr_accessor :version
    alias :to_s :version

    def initialize(version)
      self.version = version.to_s.strip
    end

    def segments
      version.scan(/\d+\-\d+|\d+[a-zA-Z]+$|\d+|[A-Za-z][0-9A-Za-z-]*$/).map do |s|
        /^\d+$/ =~ s ? s.to_i : s
      end
    end

    def [](segment)
      segments[segment]
    end
    
    def major; self[0] end
    def minor; self[1] end
    def patch; self[2] end
    def patch_minor; self[3] end
  
    def inspect
      "#<#{self.class} #{to_s}>"
    end
    
    def ==(other)
      version == other.version
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
user_agent_parser-1.0.2 lib/user_agent_parser/version.rb
user_agent_parser-1.0.1 lib/user_agent_parser/version.rb
user_agent_parser-1.0.0 lib/user_agent_parser/version.rb