Class: GlipSdk::REST::Cache::Groups
- Inherits:
-
Object
- Object
- GlipSdk::REST::Cache::Groups
- Defined in:
- lib/glip_sdk/rest/cache/groups.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#groups_name2id ⇒ Object
Returns the value of attribute groups_name2id.
-
#teams ⇒ Object
Returns the value of attribute teams.
-
#teams_name2id ⇒ Object
Returns the value of attribute teams_name2id.
Instance Method Summary collapse
- #by_name(name) ⇒ Object
- #group_by_name(name) ⇒ Object
- #id_by_name(name) ⇒ Object
-
#initialize ⇒ Groups
constructor
A new instance of Groups.
- #load_group(group) ⇒ Object
- #load_groups(groups) ⇒ Object
- #team_by_name(name) ⇒ Object
Constructor Details
#initialize ⇒ Groups
Returns a new instance of Groups.
7 8 9 10 11 12 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 7 def initialize @groups = {} @teams = {} @teams_name2id = {} @groups_name2id = {} end |
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
3 4 5 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 3 def groups @groups end |
#groups_name2id ⇒ Object
Returns the value of attribute groups_name2id.
4 5 6 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 4 def groups_name2id @groups_name2id end |
#teams ⇒ Object
Returns the value of attribute teams.
5 6 7 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 5 def teams @teams end |
#teams_name2id ⇒ Object
Returns the value of attribute teams_name2id.
6 7 8 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 6 def teams_name2id @teams_name2id end |
Instance Method Details
#by_name(name) ⇒ Object
41 42 43 44 45 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 41 def by_name(name) team = team_by_name name return team unless team.nil? group_by_name name end |
#group_by_name(name) ⇒ Object
52 53 54 55 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 52 def group_by_name(name) group_id = @groups_name2id[name.to_s] group_id ? @groups[group_id] : nil end |
#id_by_name(name) ⇒ Object
36 37 38 39 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 36 def id_by_name(name) group = by_name name group.nil? ? nil : group['id'] end |
#load_group(group) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 22 def load_group(group) if group.key? 'id' id = group['id'] type = group['type'] if type.to_s.downcase == 'team' @teams[id.to_s] = group @teams_name2id[group['name']] = id.to_s else @groups[id.to_s] = group @groups_name2id[group['name']] = id.to_s end end end |
#load_groups(groups) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 14 def load_groups(groups) if groups.is_a? Array groups.each { |g| load_group g } elsif groups.is_a? Hash groups.each { |_, g| load_group g} end end |
#team_by_name(name) ⇒ Object
47 48 49 50 |
# File 'lib/glip_sdk/rest/cache/groups.rb', line 47 def team_by_name(name) team_id = @teams_name2id[name.to_s] team_id ? @teams[team_id] : nil end |