Sha256: d69f22b50388ab698877c8ad1ae03211f07759012101f15ed8b1937e7b393d8b

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Droiuby
  class Android
    class Otherwise
      
      def initialize
      end
      
      def otherwise(&block)
        @return_value = block.call
      end
      
      def value
        @return_value
      end
    end

    class DummyOtherwise
      
      def initialize(return_value)
        @return_value = return_value
      end
      
      def otherwise(&block)
        @return_value
      end
      
      def value
        @return_value
      end
    end

    def self.when_api(verb, level, &block)
      current_api_level = Java::android.os.Build::VERSION::SDK_INT
      case verb
      when :greater_than
        if current_api_level > level
          return DummyOtherwise.new(block.call)
        end
      when :less_than
        if current_api_level < level
          block.call
          return DummyOtherwise.new(block.call)
        end
      when :at_least
        if current_api_level >= level
          block.call
          return DummyOtherwise.new(block.call)
        end
      when :at_most
        if current_api_level <= level
          block.call
          return DummyOtherwise.new(block.call)
        end
      end
      return Otherwise.new
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
droiuby-0.2.0 lib/droiuby/android.rb