Class: WebTranslateIt::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/web_translate_it/util.rb

Overview

A few useful functions

Class Method Summary collapse

Class Method Details

.calculate_percentage(processed, total) ⇒ Object



30
31
32
33
# File 'lib/web_translate_it/util.rb', line 30

def self.calculate_percentage(processed, total)
  return 0 if total == 0
  ((processed*10)/total).to_f.ceil*10
end

.http_connection {|http| ... } ⇒ Object

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

Yields:

  • (http)


22
23
24
25
26
27
28
# File 'lib/web_translate_it/util.rb', line 22

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

.versionObject

Return a string representing the gem version For example “1.4.4”



8
9
10
11
# File 'lib/web_translate_it/util.rb', line 8

def self.version
  hash = YAML.load_file File.join(File.dirname(__FILE__), '..', '..' '/version.yml')
  [hash[:major], hash[:minor], hash[:patch]].join('.')
end