Class: Talkable::Origin

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/talkable/resources/origin.rb

Class Method Summary collapse

Class Method Details

.parse(result_hash) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/talkable/resources/origin.rb', line 5

def self.parse(result_hash)
  return nil unless result_hash && result_hash[:origin] &&  result_hash[:origin].size > 0
  origin_hash = result_hash[:origin]
  order_date = (origin_hash ? origin_hash[:order_date] : nil)

  if order_date
    origin_hash[:order_date] = begin
      Time.iso8601(order_date)
    rescue ArgumentError
      order_date
    end
  end

  origin = self.new(origin_hash)
  origin.offer ||= Talkable::Offer.parse(result_hash)
  origin
end