class Twoffein::Profile
Public Class Methods
get(profile="")
click to toggle source
# File lib/twoffein-client/profile.rb, line 23 def self.get(profile="") new(HTTP.get("profile", :profile => profile)) end
new(hash=nil)
click to toggle source
Calls superclass method
# File lib/twoffein-client/profile.rb, line 18 def initialize(hash=nil) return super(*hash) if hash.nil? hash.each { |key,val| self[key] = val if members.include? key } end
Public Instance Methods
to_s()
click to toggle source
# File lib/twoffein-client/profile.rb, line 27 def to_s hash = instance_hash max_length = hash.keys.map { |k| k.length }.max hash.map { |attr, value| attr = attr.to_sym if attr == :first_login value = human_readable_time(value) end postfix = ":" attr = human_readable_key(attr) + postfix "#{attr.to_s.ljust(max_length+postfix.length+1)}#{value}" }.join("\n") end
Private Instance Methods
human_readable_key(key)
click to toggle source
# File lib/twoffein-client/profile.rb, line 53 def human_readable_key(key) key.to_s.gsub('_', ' ').split(/(\W)/).map(&:capitalize).join end
human_readable_time(value)
click to toggle source
# File lib/twoffein-client/profile.rb, line 57 def human_readable_time(value) Time.at(value.to_i).strftime("%Y-%m-%d %H:%M") end
instance_hash()
click to toggle source
# File lib/twoffein-client/profile.rb, line 47 def instance_hash members.reduce({}) do |hash, ivar| hash.merge({ivar.to_sym => self[ivar]}) end end