Sha256: eff8dde49d6e503099b0fa6d3cd8839706e522e4a7722703b4083424afcce888
Contents?: true
Size: 1.84 KB
Versions: 3
Compression:
Stored size: 1.84 KB
Contents
module GoogleApps module Atom class Nickname include Atom::Node include Atom::Document attr_reader :nickname, :user, :document ELEMENTS = { nick: ['apps:nickname', 'name'], user: ['apps:login', 'userName'] } def initialize(xml = nil) @document = Atom::XML::Document.new @document.root = build_root 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(@document, '//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(@document, '//apps:login', userName: [@user, username]) : create('login', username) @user = username end # to_s returns the underlying XML document as a string. def to_s @document.to_s end private # create adds the specified node to @document. 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' @document.root << create_node(type: 'apps:nickname', attrs: [['name', value]]) when 'login' @document.root << create_node(type: 'apps:login', attrs: [['userName', value]]) end @document = parse @document end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
google_apps-0.4.9.9 | lib/google_apps/atom/nickname.rb |
google_apps-0.4.9.2 | lib/google_apps/atom/nickname.rb |
google_apps-0.4.9.1 | lib/google_apps/atom/nickname.rb |