Class: EzLinkedin::Mash

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

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



8
9
10
11
# File 'lib/ezlinkedin/mash.rb', line 8

def self.from_json(json_string)
  result_hash = ::MultiJson.decode(json_string)
  new(result_hash)
end

Instance Method Details

#timestampObject



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

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



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

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