Class: Formotion::RowType::CurrencyRow

Inherits:
NumberRow show all
Defined in:
lib/formotion/row_type/currency_row.rb

Constant Summary

Constants inherited from StringRow

StringRow::TEXT_FIELD_TAG

Instance Attribute Summary

Attributes inherited from Base

#row, #tableView

Instance Method Summary collapse

Methods inherited from NumberRow

#keyboardType

Methods inherited from StringRow

#add_callbacks, #build_cell, #done_editing, #keyboardType, #on_select, #update_text_field

Methods inherited from Base

#_on_select, #after_build, #after_delete, #break_with_semaphore, #build_cell, #button?, #cellEditingStyle, #cell_style, #delete_row, #done_editing, field_buffer, #indentWhileEditing?, #initialize, #input_accessory_view, #on_delete, #on_select, #update_cell, #with_semaphore

Constructor Details

This class inherits a constructor from Formotion::RowType::Base

Instance Method Details

#on_change(text_field) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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_valueObject



22
23
24
# File 'lib/formotion/row_type/currency_row.rb', line 22

def row_value
  number_formatter.stringFromNumber super.to_f
end

#value_for_save_hashObject



26
27
28
# File 'lib/formotion/row_type/currency_row.rb', line 26

def value_for_save_hash
  number_formatter.numberFromString(row_value)
end