Class: ConvertDate
- Inherits:
-
Object
- Object
- ConvertDate
- Defined in:
- lib/salary_croatia/convert_date.rb
Instance Method Summary collapse
- #get_date(date) ⇒ Object
- #get_dates(dates_array = []) ⇒ Object
-
#transform_date(date) ⇒ Object
transform date considering the type of input -> ((month + year) && (day + month + year)) ALLOWED!.
Instance Method Details
#get_date(date) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/salary_croatia/convert_date.rb', line 12 def get_date(date) start_string = date.split(" ")[0] end_string = date.split(" ")[1] helper_hash = { "I." => "01.", "II." => "02.", "III." => "03.", "IV." => "04.", "V." => "05.", "VI." => "06.", "VII." => "07.", "VIII." => "08.", "IX." => "09.", "X." => "10.", "XI." => "11.", "XII." => "12." } "01." + helper_hash[start_string] + end_string end |
#get_dates(dates_array = []) ⇒ Object
6 7 8 9 10 |
# File 'lib/salary_croatia/convert_date.rb', line 6 def get_dates(dates_array = []) formatted_dates = dates_array.map do |date| get_date(date) end end |
#transform_date(date) ⇒ Object
transform date considering the type of input -> ((month + year) && (day + month + year)) ALLOWED!
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/salary_croatia/convert_date.rb', line 35 def transform_date(date) delimiter = date.tr("0-9", "")[0] # Removing digits and returning first non-numeric character date_array = date.split(delimiter) # Splitting date input by its delimiter if date_array.size > 2 first_element = date_array[0] date_array.delete_at(date_array.find_index(first_element)) end return "01." + date_array.join(".") + "." end |