Class: Money::Bank::GoogleCurrency

Inherits:
VariableExchange
  • Object
show all
Defined in:
lib/money/bank/google_currency.rb

Constant Summary

SERVICE_HOST =
"www.google.com"
SERVICE_PATH =
"/ig/calculator"

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Hash) rates (readonly)

Stores the currently known rates.

Returns:

  • (Hash)

    Stores the currently known rates.



13
14
15
# File 'lib/money/bank/google_currency.rb', line 13

def rates
  @rates
end

Instance Method Details

- (Float) flush_rate(from, to)

Clears the specified rate stored in @rates.

Examples:

@bank = GoogleCurrency.new    #=> <Money::Bank::GoogleCurrency...>
@bank.get_rate(:USD, :EUR)    #=> 0.776337241
@bank.flush_rate(:USD, :EUR)  #=> 0.776337241

Parameters:

  • (String, Symbol, Currency) from

    Currency to convert from (used for key into @rates).

  • (String, Symbol, Currency) to

    Currency to convert to (used for key into @rates).

Returns:

  • (Float)

    The flushed rate.



44
45
46
47
48
49
# File 'lib/money/bank/google_currency.rb', line 44

def flush_rate(from, to)
  key = rate_key_for(from, to)
  @mutex.synchronize{
    @rates.delete(key)
  }
end

- (Hash) flush_rates

Clears all rates stored in @rates

Examples:

@bank = GoogleCurrency.new  #=> <Money::Bank::GoogleCurrency...>
@bank.get_rate(:USD, :EUR)  #=> 0.776337241
@bank.flush_rates           #=> {}

Returns:

  • (Hash)

    The empty @rates Hash.



24
25
26
27
28
# File 'lib/money/bank/google_currency.rb', line 24

def flush_rates
  @mutex.synchronize{
    @rates = {}
  }
end

- (Float) get_google_rate(from, to)

Deprecated.

Returns the requested rate after querying Google.

Examples:

@bank = GoogleCurrency.new         #=> <Money::Bank::GoogleCurrency...>
@bank.get_google_rate(:USD, :EUR)  #=> 0.776337241

Parameters:

  • (String, Symbol, Currency) from

    Currency to convert from

  • (String, Symbol, Currency) to

    Currency to convert to

Returns:

  • (Float)

    The requested rate.



81
82
83
84
# File 'lib/money/bank/google_currency.rb', line 81

def get_google_rate(from, to)
  warn "#get_google_rate is deprecated, please use #get_rate"
  fetch_rate(from, to)
end

- (Float) get_rate(from, to)

Returns the requested rate.

Examples:

@bank = GoogleCurrency.new  #=> <Money::Bank::GoogleCurrency...>
@bank.get_rate(:USD, :EUR)  #=> 0.776337241

Parameters:

  • (String, Symbol, Currency) from

    Currency to convert from

  • (String, Symbol, Currency) to

    Currency to convert to

Returns:

  • (Float)

    The requested rate.



62
63
64
65
66
# File 'lib/money/bank/google_currency.rb', line 62

def get_rate(from, to)
  @mutex.synchronize{
    @rates[rate_key_for(from, to)] ||= fetch_rate(from, to)
  }
end