class Formotion::RowType::CurrencyRow

Public Instance Methods

on_change(text_field) click to toggle source
# File lib/formotion/row_type/currency_row.rb, line 6
def on_change(text_field)
  break_with_semaphore do
    edited_text = text_field.text
    entered_digits = edited_text.gsub %r{\D+}, ''
    decimal_num = 0.0

    if !entered_digits.empty?
      decimal_num = entered_digits.to_i * (10 ** currency_scale.to_i)
      decimal_num = decimal_num.to_f
    end

    row.value = decimal_num
    text_field.text = row_value
  end
end
row_value() click to toggle source
Calls superclass method
# File lib/formotion/row_type/currency_row.rb, line 22
def row_value
  number_formatter.stringFromNumber super.to_f
end
value_for_save_hash() click to toggle source
# File lib/formotion/row_type/currency_row.rb, line 26
def value_for_save_hash
  number_formatter.numberFromString(row_value)
end

Private Instance Methods

currency_scale() click to toggle source
# File lib/formotion/row_type/currency_row.rb, line 40
def currency_scale
  @currency_scale ||= number_formatter.maximumFractionDigits * -1
end
number_formatter() click to toggle source
# File lib/formotion/row_type/currency_row.rb, line 31
def number_formatter
  @number_formatter ||= begin
    formatter = NSNumberFormatter.alloc.init
    formatter.numberStyle = NSNumberFormatterCurrencyStyle
    formatter.locale = NSLocale.currentLocale
    formatter
  end
end