class LinkedIn::Mash
The generalized pseudo-object that is returned for all query requests.
Public Class Methods
from_json(json_string)
click to toggle source
Convert a json string to a Mash
@param [String] json_string @return [LinkedIn::Mash]
# File lib/linked_in/mash.rb, line 14 def self.from_json(json_string) result_hash = ::MultiJson.decode(json_string) new(result_hash) end
Public Instance Methods
all()
click to toggle source
Return the results array from the query
@return [Array]
Calls superclass method
# File lib/linked_in/mash.rb, line 57 def all super || [] end
id()
click to toggle source
Returns the id of the object from LinkedIn
@return [String]
# File lib/linked_in/mash.rb, line 33 def id if self['id'] self['id'] else self['_key'] end end
timestamp()
click to toggle source
Convert the 'timestamp' field from a string to a Time object
@return [Time]
# File lib/linked_in/mash.rb, line 44 def timestamp value = self['timestamp'] if value.kind_of? Integer value = value / 1000 if value > 9999999999 Time.at(value) else value end end
to_date()
click to toggle source
Returns a Date if we have year, month and day, and no conflicting key
@return [Date]
Calls superclass method
# File lib/linked_in/mash.rb, line 22 def to_date if !self.has_key?('to_date') && contains_date_fields? Date.civil(self.year, self.month, self.day) else super end end
Protected Instance Methods
contains_date_fields?()
click to toggle source
# File lib/linked_in/mash.rb, line 63 def contains_date_fields? self.year? && self.month? && self.day? end
convert_key(key)
click to toggle source
overload the convert_key
mash method so that the LinkedIn
keys are made a little more ruby-ish
# File lib/linked_in/mash.rb, line 69 def convert_key(key) case key.to_s when '_total' 'total' when 'values' 'all' when 'numResults' 'total_results' else underscore(key) end end
underscore(camel_cased_word)
click to toggle source
borrowed from ActiveSupport no need require an entire lib when we only need one method
# File lib/linked_in/mash.rb, line 84 def underscore(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end