Class: LiveData::Channel
- Inherits:
-
Object
- Object
- LiveData::Channel
- Defined in:
- lib/live_data/channel.rb
Overview
Channel is used to maintain users, groups and user-group relation
Instance Attribute Summary collapse
-
#group_have_users ⇒ Object
Returns the value of attribute group_have_users.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#name ⇒ Object
Returns the value of attribute name.
-
#user_in_groups ⇒ Object
Returns the value of attribute user_in_groups.
-
#users ⇒ Object
Returns the value of attribute users.
Instance Method Summary collapse
-
#create_group(name) ⇒ Object
Create a group, if the group is not present in the group list ==== Parameters *
name- Group name. -
#create_user(name) ⇒ Object
Create a user, if he is not present in the user list ==== Parameters *
name- User name. -
#destroy ⇒ Object
Destroy current channel.
-
#destroy_group(name) ⇒ Object
Destroy a group ==== Parameters *
name- Group name. -
#destroy_user(name) ⇒ Object
Destroy a user ==== Parameters *
name- User name. -
#get_group(name) ⇒ Object
Get group object.
-
#get_user(name) ⇒ Object
Get user object.
-
#initialize(name = nil) ⇒ Channel
constructor
Create a new channel.
-
#write(data) ⇒ Object
Write data in any format ==== Parameters *
data- it may be any Object. -
#write_json(json_data) ⇒ Object
Write json data ==== Parameters *
json_data- String which contain data in json format. -
#write_yaml(yaml_data) ⇒ Object
Write yaml data ==== Parameters *
yaml_data- String which contain data in yaml format.
Constructor Details
#initialize(name = nil) ⇒ Channel
Create a new channel
14 15 16 17 18 19 20 |
# File 'lib/live_data/channel.rb', line 14 def initialize( name = nil ) @name = name || self @users = {} @groups = {} @user_in_groups = {} @group_have_users = {} end |
Instance Attribute Details
#group_have_users ⇒ Object
Returns the value of attribute group_have_users.
10 11 12 |
# File 'lib/live_data/channel.rb', line 10 def group_have_users @group_have_users end |
#groups ⇒ Object
Returns the value of attribute groups.
8 9 10 |
# File 'lib/live_data/channel.rb', line 8 def groups @groups end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/live_data/channel.rb', line 11 def name @name end |
#user_in_groups ⇒ Object
Returns the value of attribute user_in_groups.
9 10 11 |
# File 'lib/live_data/channel.rb', line 9 def user_in_groups @user_in_groups end |
#users ⇒ Object
Returns the value of attribute users.
7 8 9 |
# File 'lib/live_data/channel.rb', line 7 def users @users end |
Instance Method Details
#create_group(name) ⇒ Object
Create a group, if the group is not present in the group list
Parameters
-
name- Group name
63 64 65 66 67 68 69 |
# File 'lib/live_data/channel.rb', line 63 def create_group( name ) unless( @groups[name] ) @groups[name] = LiveData::Group.new( name, self ) @group_have_users[name] = @groups[name].users end return @groups[name] end |
#create_user(name) ⇒ Object
Create a user, if he is not present in the user list
Parameters
-
name- User name
52 53 54 55 56 57 58 |
# File 'lib/live_data/channel.rb', line 52 def create_user( name ) unless( @users[name] ) @users[name] = LiveData::User.new( name, self ) @user_in_groups[name] = @users[name].groups end return @users[name] end |
#destroy ⇒ Object
Destroy current channel
97 98 99 100 101 102 103 104 |
# File 'lib/live_data/channel.rb', line 97 def destroy @users.each{|name,obj| obj.destroy() } @groups.each{|name,obj| obj.destroy() } end |
#destroy_group(name) ⇒ Object
Destroy a group
Parameters
-
name- Group name
92 93 94 |
# File 'lib/live_data/channel.rb', line 92 def destroy_group( name ) @groups[name].destroy() end |
#destroy_user(name) ⇒ Object
Destroy a user
Parameters
-
name- User name
84 85 86 |
# File 'lib/live_data/channel.rb', line 84 def destroy_user( name ) @users[name].destroy() end |
#get_group(name) ⇒ Object
Get group object
77 78 79 |
# File 'lib/live_data/channel.rb', line 77 def get_group( name ) @groups[name] end |
#get_user(name) ⇒ Object
Get user object
72 73 74 |
# File 'lib/live_data/channel.rb', line 72 def get_user( name ) @users[name] end |
#write(data) ⇒ Object
Write data in any format
Parameters
-
data- it may be any Object.
43 44 45 46 47 |
# File 'lib/live_data/channel.rb', line 43 def write( data ) @users.each{|user_name, user| user.write( data ) } end |
#write_json(json_data) ⇒ Object
Write json data
Parameters
-
json_data- String which contain data in json format
34 35 36 37 38 |
# File 'lib/live_data/channel.rb', line 34 def write_json( json_data ) @users.each{|user_name, user| user.write_json( json_data ) } end |
#write_yaml(yaml_data) ⇒ Object
Write yaml data
Parameters
-
yaml_data- String which contain data in yaml format
25 26 27 28 29 |
# File 'lib/live_data/channel.rb', line 25 def write_yaml( yaml_data ) @users.each{|user_name, user| user.write_yaml( yaml_data ) } end |