class TdTip::Models::Parameters

Storing and processing parameters

Attributes

amount[R]
currency[R]
tip[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/td_tip/models/parameters.rb, line 15
def initialize(options = {})
  @tip = options[:tip].blank? ? DEFAULT_TIP : options[:tip]
  parse_amount options[:amount]
end

Public Instance Methods

to_params() click to toggle source

Returns parameters for Web Service

# File lib/td_tip/models/parameters.rb, line 21
def to_params
  { amount: amount, tip: tip }
end

Protected Instance Methods

parse_amount(amount_raw) click to toggle source

Parses raw amount into final amount and currency

# File lib/td_tip/models/parameters.rb, line 28
def parse_amount(amount_raw)
  matches = TdTip::AMOUNT_CURRENCY_REGEXP.match amount_raw
  return unless matches
  @amount = matches.captures[0].sub(',', '.').to_f
  @currency = matches.captures[1].to_s
end