Class: LinkedIn::Mash
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- LinkedIn::Mash
- 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
-
.from_json(json_string) ⇒ Object
a simple helper to convert a json string to a Mash.
Instance Method Summary collapse
- #timestamp ⇒ Object
-
#to_date ⇒ Object
returns a Date if we have year, month and day, and no conflicting key.
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
#timestamp ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/linked_in/mash.rb', line 21 def value = self['timestamp'] if value.kind_of? Integer value = value / 1000 if value > 9999999999 Time.at(value) else value end end |
#to_date ⇒ Object
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 |