Sha256: ec142f15487fe277c6ee2a54441084b2b2dd605feda9de466793dce8d48fc9f0

Contents?: true

Size: 1023 Bytes

Versions: 6

Compression:

Stored size: 1023 Bytes

Contents

module WebTranslateIt
  
  # A few useful functions
  class Util
    
    # Return a string representing the gem version
    # For example "1.4.4"
    def self.version
      hash = YAML.load_file File.join(File.dirname(__FILE__), '..', '..' '/version.yml')
      [hash[:major], hash[:minor], hash[:patch]].join('.')
    end
    
    # Yields a HTTP connection over SSL to Web Translate It.
    # This is used for the connections to the API throughout the library.
    # Use it like so:
    # 
    #   WebTranslateIt::Util.http_connection do |http|
    #     request = Net::HTTP::Get.new(api_url)
    #     response = http.request(request)
    #   end
    #
    def self.http_connection
      http = Net::HTTP.new('webtranslateit.com', 443)
      http.use_ssl      = true
      http.verify_mode  = OpenSSL::SSL::VERIFY_NONE
      http.read_timeout = 40
      yield http
    end
    
    def self.calculate_percentage(processed, total)
      return 0 if total == 0
      ((processed*10)/total).to_f.ceil*10
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
wti_gettext_i18n_rails-1.0.3 lib/web_translate_it/util.rb
wti_gettext_i18n_rails-1.0.2 lib/web_translate_it/util.rb
wti_gettext_i18n_rails-1.0.1 lib/web_translate_it/util.rb
wti_gettext_i18n_rails-1.0.0 lib/web_translate_it/util.rb
web_translate_it-1.5.2 lib/web_translate_it/util.rb
web_translate_it-1.5.1 lib/web_translate_it/util.rb