Sha256: 0c65c31ad5551021423b48cd7f73564980c47bec02d099983778df4261b48e74
Contents?: true
Size: 1.72 KB
Versions: 2
Compression:
Stored size: 1.72 KB
Contents
module GoogleApps module Atom class Nickname < Document attr_reader :nickname, :user, :doc MAP = { name: :nickname, userName: :user } def initialize(xml = nil) super(xml, MAP) @doc.root = build_root(:nickname) unless xml end # nickname= sets the nickname value on the object and in the # underlying XML document. It takes a string as an argument. # # nickname = 'Timmy' # # nickname= returns the new nickname value def nickname=(nick) @nickname ? find_and_update('//apps:nickname', name: [@nickname, nick]) : create('nickname', nick) @nickname = nick end # user= sets the username value on the object and in the # underlying XML document. It takes a string (default/current username) # as an argument. # # user = 'tom' # # user= returns the new username value def user=(username) @user ? find_and_update('//apps:login', userName: [@user, username]) : create('login', username) @user = username end # to_s returns the underlying XML document as a string. def to_s @doc.to_s end private # create adds the specified node to @doc. It takes # a type and a value as arguments. # # create 'nickname', 'Bob' # # create returns a parsed copy of the document. def create(type, value) case type when 'nickname' @doc.root << create_node(type: 'apps:nickname', attrs: [['name', value]]) when 'login' @doc.root << create_node(type: 'apps:login', attrs: [['userName', value]]) end @doc = parse @doc end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
google_apps-0.9 | lib/google_apps/atom/nickname.rb |
google_apps-0.5 | lib/google_apps/atom/nickname.rb |