OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / lib / operator.rb
1 class Operator
2   
3   def initialize operators
4     @operators = operators
5     @operators = [@operators] unless @operators.respond_to?(:each)
6     @operators.compact!
7   end
8   
9   #InstanceMethods
10   def find_author
11     @operators.each do |operator|
12       return operator if operator.is_a?(Author)
13       return operator.author if operator.is_a?(User)
14       return operator.user.author if operator.is_a?(Artist) and operator.user.author
15     end
16     nil
17   end
18   
19   def find_artist
20     @operators.each do |operator|
21       return operator.user.artist if operator.is_a?(Author) and operator.user.artist
22       return operator.artist if operator.is_a?(User)
23       return operator if operator.is_a?(Artist)
24     end
25     nil
26   end
27   
28   def find_admin
29     @operators.each do |operator|
30       return operator if operator.is_a?(Admin)
31     end
32     nil
33   end
34   
35   def author
36     return @author if @author
37     @author = find_author
38   end
39   
40   def artist
41     return @artist if @artist
42     @artist = find_artist
43   end
44   
45   def admin
46     return @admin if @admin
47     @admin = find_admin
48   end
49   
50   def guest?
51     true
52   end
53   
54   def reader?
55     @operators.each do |operator|
56       return true if operator.is_a?(Author) or operator.is_a?(Artist) or operator.is_a?(Admin) or operator.is_a?(User)
57     end
58     false
59   end
60   
61   def user?
62     @operators.each do |operator|
63       return true if operator.is_a?(Author) or operator.is_a?(Artist) or operator.is_a?(User)
64     end
65     false
66   end
67   
68   def resource_reader?
69     @operators.each do |operator|
70       return true if operator.is_a?(Author) or operator.is_a?(Artist) or operator.is_a?(Admin) or operator.is_a?(User) or operator.is_a?(DemandUser)
71     end
72     false
73   end
74   
75   def admin?
76     @operators.each do |operator|
77       return true if operator.is_a?(Admin)
78     end
79     false
80   end
81   
82 end