Module: Smtpcom::Sendapi::Utils
- Defined in:
- lib/smtpcom/sendapi/utils.rb
Class Method Summary collapse
- .format_response_row(row) ⇒ Object
- .parse_time(str) ⇒ Object
- .underscore(str) ⇒ Object
- .underscore_hash(h) ⇒ Object
Class Method Details
.format_response_row(row) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/smtpcom/sendapi/utils.rb', line 21 def format_response_row(row) row.each do |k, v| row[k] = parse_time(v) if v.is_a?(String) && v =~ /\/Date\(\d{13}\)\// end underscore_hash(row) .reject { |k, _v| k.start_with? '_' } .inject({}) { |res, (k, v)| res[k.to_sym] = v; res } end |
.parse_time(str) ⇒ Object
17 18 19 |
# File 'lib/smtpcom/sendapi/utils.rb', line 17 def parse_time(str) Time.at(str.scan(/\d{13}/).first.to_i / 1000) end |
.underscore(str) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/smtpcom/sendapi/utils.rb', line 5 def underscore(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .downcase end |
.underscore_hash(h) ⇒ Object
13 14 15 |
# File 'lib/smtpcom/sendapi/utils.rb', line 13 def underscore_hash(h) Hash[h.map { |k, v| [Utils.underscore(k), v] }] end |