Module: Cda::XmlBuilder::Helpers
- Included in:
- Cda::XmlBuilder
- Defined in:
- lib/cda/xml_builder.rb
Instance Method Summary collapse
- #apply_format(value, format) ⇒ Object
- #auto_format(value) ⇒ Object
- #determine_format(value) ⇒ Object
- #format_array(array) ⇒ Object
- #format_date(time) ⇒ Object
- #format_datetime(time) ⇒ Object
- #format_human_date(time) ⇒ Object
- #format_human_datetime(time) ⇒ Object
Instance Method Details
#apply_format(value, format) ⇒ Object
26 27 28 |
# File 'lib/cda/xml_builder.rb', line 26 def apply_format(value, format) send("format_#{format}", value) end |
#auto_format(value) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/cda/xml_builder.rb', line 43 def auto_format(value) if (format = determine_format(value)) apply_format(value, format) else value.to_s end end |
#determine_format(value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cda/xml_builder.rb', line 30 def determine_format(value) case value when Time, DateTime :datetime when Date :date when Array :array else nil end end |
#format_array(array) ⇒ Object
22 23 24 |
# File 'lib/cda/xml_builder.rb', line 22 def format_array(array) array.join(" ") end |
#format_date(time) ⇒ Object
10 11 12 |
# File 'lib/cda/xml_builder.rb', line 10 def format_date(time) time.presence && Cda::ValueCoercer.date_to_string(time) || '' end |
#format_datetime(time) ⇒ Object
6 7 8 |
# File 'lib/cda/xml_builder.rb', line 6 def format_datetime(time) time.presence && Cda::ValueCoercer.date_time_to_string(time) || '' end |
#format_human_date(time) ⇒ Object
18 19 20 |
# File 'lib/cda/xml_builder.rb', line 18 def format_human_date(time) time.presence && Medapp::Formatting.format_date(time) || '' end |
#format_human_datetime(time) ⇒ Object
14 15 16 |
# File 'lib/cda/xml_builder.rb', line 14 def format_human_datetime(time) Medapp::Formatting.format_datetime(time) || '' end |