Class: LinkedIn::Mash

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/linked_in/mash.rb

Overview

Coerces LinkedIn JSON to a nice Ruby hash LinkedIn::Mash inherits from Hashie::Mash

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(json_string) ⇒ Object

a simple helper to convert a json string to a Mash


7
8
9
10
# File 'lib/linked_in/mash.rb', line 7

def self.from_json(json_string)
  result_hash = JSON.load(json_string)
  new(result_hash)
end

Instance Method Details

#timestampObject


21
22
23
24
25
26
27
28
29
# File 'lib/linked_in/mash.rb', line 21

def timestamp
  value = self['timestamp']
  if value.kind_of? Integer
    value = value / 1000 if value > 9999999999
    Time.at(value)
  else
    value
  end
end

#to_dateObject

returns a Date if we have year, month and day, and no conflicting key


13
14
15
16
17
18
19
# File 'lib/linked_in/mash.rb', line 13

def to_date
  if !self.has_key?('to_date') && contains_date_fields?
    Date.civil(self.year, self.month, self.day)
  else
    super
  end
end