osm 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,88 +1,120 @@
1
1
  module Osm
2
2
 
3
3
  class Member
4
+ include ::ActiveAttr::MassAssignmentSecurity
5
+ include ::ActiveAttr::Model
4
6
 
5
- attr_reader :id, :section_id, :type, :first_name, :last_name, :email1, :email2, :email3, :email4, :phone1, :phone2, :phone3, :phone4, :address, :address2, :date_of_birth, :started, :joining_in_years, :parents, :notes, :medical, :religion, :school, :ethnicity, :subs, :grouping_id, :grouping_leader, :joined, :age, :joined_years
6
- # @!attribute [r] id
7
+ # @!attribute [rw] id
7
8
  # @return [Fixnum] the id for the member
8
- # @!attribute [r] section_id
9
+ # @!attribute [rw] section_id
9
10
  # @return [Fixnum] the section the member belongs to
10
- # @!attribute [r] type
11
- # @return [?] ?
12
- # @!attribute [r] first_name
11
+ # @!attribute [rw] type
12
+ # @return [String] ?
13
+ # @!attribute [rw] first_name
13
14
  # @return [String] the member's first name
14
- # @!attribute [r] last_name
15
+ # @!attribute [rw] last_name
15
16
  # @return [String] the member's last name
16
- # @!attribute [r] email1
17
+ # @!attribute [rw] email1
17
18
  # @return [String] the 1st email address for the member
18
- # @!attribute [r] email2
19
+ # @!attribute [rw] email2
19
20
  # @return [String] the 2nd email address for the member
20
- # @!attribute [r] email3
21
+ # @!attribute [rw] email3
21
22
  # @return [String] the 3rd email address for the member
22
- # @!attribute [r] email4
23
+ # @!attribute [rw] email4
23
24
  # @return [String] the 4th email address for the member
24
- # @!attribute [r] phone1
25
+ # @!attribute [rw] phone1
25
26
  # @return [String] the 1st phone number for the member
26
- # @!attribute [r] phone2
27
+ # @!attribute [rw] phone2
27
28
  # @return [String] the 2nd phone number for the member
28
- # @!attribute [r] phone3
29
+ # @!attribute [rw] phone3
29
30
  # @return [String] the 3rd phone number for the member
30
- # @!attribute [r] phone4
31
+ # @!attribute [rw] phone4
31
32
  # @return [String] the 4th phone number for the member
32
- # @!attribute [r] address
33
+ # @!attribute [rw] address
33
34
  # @return [String] the member's address
34
- # @!attribute [r] address2
35
+ # @!attribute [rw] address2
35
36
  # @return [String] the member's 2nd address
36
- # @!attribute [r] date_of_birth
37
+ # @!attribute [rw] date_of_birth
37
38
  # @return [Date] the member's date of birth
38
- # @!attribute [r] started
39
+ # @!attribute [rw] started
39
40
  # @return [Date] when the member started Scouting
40
- # @!attribute [r] joining_in_years
41
+ # @!attribute [rw] joining_in_years
41
42
  # @return [Fixnum] ?
42
- # @!attribute [r] parents
43
+ # @!attribute [rw] parents
43
44
  # @return [String] the member's parent's names
44
- # @!attribute [r] notes
45
+ # @!attribute [rw] notes
45
46
  # @return [String] notes relating to the member
46
- # @!attribute [r] medical
47
+ # @!attribute [rw] medical
47
48
  # @return [String] the member's key medical details
48
- # @!attribute [r] religion
49
+ # @!attribute [rw] religion
49
50
  # @return [String] the member's religion
50
- # @!attribute [r] school
51
+ # @!attribute [rw] school
51
52
  # @return [String] the school the member attends
52
- # @!attribute [r] ethnicity
53
+ # @!attribute [rw] ethnicity
53
54
  # @return [String] the member's ethnicity
54
- # @!attribute [r] subs
55
+ # @!attribute [rw] subs
55
56
  # @return [String] details about the member's subs
56
- # @!attribute [r] grouping_id
57
+ # @!attribute [rw] grouping_id
57
58
  # @return [Fixnum] the grouping within the section that the member belongs to
58
- # @!attribute [r] grouping_leader
59
+ # @!attribute [rw] grouping_leader
59
60
  # @return [Fixnum] wether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL)
60
- # @!attribute [r] joined
61
+ # @!attribute [rw] joined
61
62
  # @return [Date] when the member joined the section
62
- # @!attribute [r] age
63
+ # @!attribute [rw] age
63
64
  # @return [String] the member's current age (yy/mm)
64
- # @!attribute [r] joining_years
65
+ # @!attribute [rw] joined_years
65
66
  # @return [Fixnum] how many years the member has been in Scouting
66
67
 
68
+ attribute :id, :type => Integer
69
+ attribute :section_id, :type => Integer
70
+ attribute :type, :type => String
71
+ attribute :first_name, :type => String
72
+ attribute :last_name, :type => String
73
+ attribute :email1, :type => String, :default => ''
74
+ attribute :email2, :type => String, :default => ''
75
+ attribute :email3, :type => String, :default => ''
76
+ attribute :email4, :type => String, :default => ''
77
+ attribute :phone1, :type => String, :default => ''
78
+ attribute :phone2, :type => String, :default => ''
79
+ attribute :phone3, :type => String, :default => ''
80
+ attribute :phone4, :type => String, :default => ''
81
+ attribute :address, :type => String, :default => ''
82
+ attribute :address2, :type => String, :default => ''
83
+ attribute :date_of_birth, :type => Date
84
+ attribute :started, :type => Date
85
+ attribute :joining_in_years, :type => Integer
86
+ attribute :parents, :type => String, :default => ''
87
+ attribute :notes, :type => String, :default => ''
88
+ attribute :medical, :type => String, :default => ''
89
+ attribute :religion, :type => String, :default => ''
90
+ attribute :school, :type => String, :default => ''
91
+ attribute :ethnicity, :type => String, :default => ''
92
+ attribute :subs, :type => String, :default => ''
93
+ attribute :grouping_id, :type => Integer
94
+ attribute :grouping_leader, :type => Integer
95
+ attribute :joined, :type => Date
96
+ attribute :age, :type => String
97
+ attribute :joined_years, :type => Integer
67
98
 
68
- # Initialize a new Member
69
- # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
70
- def initialize(attributes={})
71
- [:id, :section_id, :grouping_leader].each do |attribute|
72
- raise ArgumentError, ":#{attribute} must be nil or a Fixnum >= 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] >= 0)
73
- end
74
- raise ArgumentError, ':grouping_id must be nil or a Fixnum >= -2' unless attributes[:grouping_id].nil? || (attributes[:grouping_id].is_a?(Fixnum) && attributes[:grouping_id] >= -2)
75
- raise ArgumentError, ':joined_years must be nil or a Fixnum >= -1' unless attributes[:joined_years].nil? || (attributes[:joined_years].is_a?(Fixnum) && attributes[:joined_years] >= -1)
76
- raise ArgumentError, ':joining_in_years must be nil or a Fixnum' unless attributes[:joining_in_years].nil? || attributes[:joining_in_years].is_a?(Fixnum)
77
- [:type, :first_name, :last_name, :email1, :email2, :email3, :email4, :phone1, :phone2, :phone3, :phone4, :address, :address2, :parents, :notes, :medical, :religion, :school, :ethnicity, :subs, :age].each do |attribute|
78
- raise ArgumentError, ":#{attribute} must be nil or a String" unless attributes[attribute].nil? || attributes[attribute].is_a?(String)
79
- end
80
- [:date_of_birth, :started, :joined].each do |attribute|
81
- raise ArgumentError, ":#{attribute} must be nil or a Date" unless attributes[attribute].nil? || attributes[attribute].is_a?(Date)
82
- end
99
+ attr_accessible :id, :section_id, :type, :first_name, :last_name, :email1, :email2, :email3, :email4, :phone1, :phone2, :phone3, :phone4, :address, :address2, :date_of_birth, :started, :joining_in_years, :parents, :notes, :medical, :religion, :school, :ethnicity, :subs, :grouping_id, :grouping_leader, :joined, :age, :joined_years
83
100
 
84
- attributes.each { |k,v| instance_variable_set("@#{k}", v) }
85
- end
101
+ validates_numericality_of :id, :only_integer=>true, :greater_than=>0
102
+ validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
103
+ validates_numericality_of :grouping_id, :only_integer=>true, :greater_than_or_equal_to=>-2
104
+ validates_numericality_of :grouping_leader, :only_integer=>true, :greater_than_or_equal_to=>0, :less_than_or_equal_to=>2
105
+ validates_numericality_of :joined_years, :only_integer=>true, :greater_than_or_equal_to=>-1
106
+ validates_numericality_of :joining_in_years, :only_integer=>true, :greater_than_or_equal_to=>0
107
+ validates_presence_of :first_name
108
+ validates_presence_of :last_name
109
+ validates_presence_of :date_of_birth
110
+ validates_presence_of :started
111
+ validates_presence_of :joined
112
+ validates_format_of :age, :with => /\A[0-9]{2}\/(0[0-9]|1[012])\Z/, :message => 'age is not in the correct format (yy/mm)', :allow_blank => true
113
+
114
+
115
+ # @!method initialize
116
+ # Initialize a new Term
117
+ # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
86
118
 
87
119
 
88
120
  # Initialize a new Member from api data
@@ -125,22 +157,22 @@ module Osm
125
157
  # Get the years element of this scout's age
126
158
  # @return [Fixnum] the number of years this scout has been alive
127
159
  def age_years
128
- return @age[0..1].to_i
160
+ return age[0..1].to_i
129
161
  end
130
162
 
131
163
  # Get the months element of this scout's age
132
164
  # @return [Fixnum] the number of months since this scout's last birthday
133
165
  def age_months
134
- return @age[-2..-1].to_i
166
+ return age[-2..-1].to_i
135
167
  end
136
168
 
137
169
  # Get the full name
138
170
  # @param [String] seperator what to split the scout's first name and last name with
139
171
  # @return [String] this scout's full name seperated by the optional seperator
140
172
  def name(seperator=' ')
141
- return "#{@first_name}#{seperator.to_s}#{@last_name}"
173
+ return "#{first_name}#{seperator.to_s}#{last_name}"
142
174
  end
143
175
 
144
- end
176
+ end # Class Member
145
177
 
146
- end
178
+ end # Module
@@ -1,38 +1,47 @@
1
1
  module Osm
2
2
 
3
3
  class RegisterData
4
+ include ::ActiveAttr::MassAssignmentSecurity
5
+ include ::ActiveAttr::Model
4
6
 
5
- attr_reader :member_id, :first_name, :last_name, :section_id, :grouping_id, :total, :attendance
6
- # @!attribute [r] member_id
7
+ # @!attribute [rw] member_id
7
8
  # @return [Fixnum] The OSM ID for the member
8
- # @!attribute [r] grouping_id
9
+ # @!attribute [rw] grouping_id
9
10
  # @return [Fixnum] The OSM ID for the member's grouping
10
- # @!attribute [r] section_id
11
+ # @!attribute [rw] section_id
11
12
  # @return [Fixnum] The OSM ID for the member's section
12
- # @!attribute [r] first_name
13
+ # @!attribute [rw] first_name
13
14
  # @return [String] The member's first name
14
- # @!attribute [r] last_name
15
+ # @!attribute [rw] last_name
15
16
  # @return [String] The member's last name
16
- # @!attribute [r] total
17
- # @return [FixNum] Tooltip for the field
18
- # @!attribute [r] attendance
17
+ # @!attribute [rw] total
18
+ # @return [FixNum] Total
19
+ # @!attribute [rw] attendance
19
20
  # @return [Hash] The data for each field - keys are the date, values one of 'Yes' (present), 'No' (known absence) or nil (absent)
20
21
 
21
- # Initialize a new RegisterData
22
- # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
23
- def initialize(attributes={})
24
- [:member_id, :section_id].each do |attribute|
25
- raise ArgumentError, ":#{attribute} must be nil or a Fixnum > 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] > 0)
26
- end
27
- raise ArgumentError, ':grouping_id must be nil or a Fixnum >= -2' unless attributes[:grouping_id].nil? || (attributes[:grouping_id].is_a?(Fixnum) && attributes[:grouping_id] >= -2)
28
- raise ArgumentError, ':total must be a Fixnum >= 0' unless (attributes[:total].is_a?(Fixnum) && attributes[:total] >= 0)
29
- [:first_name, :last_name].each do |attribute|
30
- raise ArgumentError, "#{attribute} must be nil or a String" unless attributes[attribute].nil? || attributes[attribute].is_a?(String)
31
- end
32
- raise ArgumentError, ':attendance must be a Hash' unless attributes[:attendance].is_a?(Hash)
22
+ attribute :member_id, :type => Integer
23
+ attribute :grouping_id, :type => Integer
24
+ attribute :section_id, :type => Integer
25
+ attribute :first_name, :type => String
26
+ attribute :last_name, :type => String
27
+ attribute :total, :type => Integer
28
+ attribute :attendance, :default => {}
33
29
 
34
- attributes.each { |k,v| instance_variable_set("@#{k}", v) }
35
- end
30
+ attr_accessible :member_id, :first_name, :last_name, :section_id, :grouping_id, :total, :attendance
31
+
32
+ validates_numericality_of :member_id, :only_integer=>true, :greater_than=>0
33
+ validates_numericality_of :grouping_id, :only_integer=>true, :greater_than_or_equal_to=>-2
34
+ validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
35
+ validates_numericality_of :total, :only_integer=>true, :greater_than_or_equal_to=>0
36
+ validates_presence_of :first_name
37
+ validates_presence_of :last_name
38
+
39
+ validates :attendance, :hash => {:key_type => Date, :value_in => ['Yes', 'No', nil]}
40
+
41
+
42
+ # @!method initialize
43
+ # Initialize a new registerData
44
+ # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
36
45
 
37
46
 
38
47
  # Initialize a new RegisterData from api data
@@ -54,6 +63,6 @@ module Osm
54
63
  new(attributes)
55
64
  end
56
65
 
57
- end
66
+ end # Class RegisterData
58
67
 
59
- end
68
+ end # Module
@@ -1,27 +1,30 @@
1
1
  module Osm
2
2
 
3
3
  class RegisterField
4
+ include ::ActiveAttr::MassAssignmentSecurity
5
+ include ::ActiveAttr::Model
4
6
 
5
- attr_reader :id, :name, :tooltip
6
- # @!attribute [r] id
7
+ # @!attribute [rw] id
7
8
  # @return [String] OSM identifier for the field
8
- # @!attribute [r] name
9
+ # @!attribute [rw] name
9
10
  # @return [String] Human readable name for the field
10
- # @!attribute [r] tooltip
11
+ # @!attribute [rw] tooltip
11
12
  # @return [String] Tooltip for the field
12
13
 
13
- # Initialize a new RegisterField
14
- # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
15
- def initialize(attributes={})
16
- [:id, :name].each do |attribute|
17
- raise ArgumentError, "#{attribute} must be a String" unless attributes[attribute].is_a?(String)
18
- end
19
- raise ArgumentError, ':tooltip must be a String' unless attributes[:tooltip].nil? || attributes[:tooltip].is_a?(String)
14
+ attribute :id, :type => String
15
+ attribute :name, :type => String
16
+ attribute :tooltip, :type => String, :default => ''
20
17
 
21
- attributes.each { |k,v| instance_variable_set("@#{k}", v) }
18
+ attr_accessible :id, :name, :tooltip
22
19
 
23
- @tooltip ||= ''
24
- end
20
+ validates_presence_of :id
21
+ validates_presence_of :name
22
+ validates_presence_of :tooltip, :allow_blank => true
23
+
24
+
25
+ # @!method initialize
26
+ # Initialize a new RegisterField
27
+ # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
25
28
 
26
29
 
27
30
  # Initialize a new RegisterField from api data
@@ -34,6 +37,6 @@ module Osm
34
37
  })
35
38
  end
36
39
 
37
- end
40
+ end # Class RegisterField
38
41
 
39
- end
42
+ end # Module
@@ -1,33 +1,48 @@
1
1
  module Osm
2
2
 
3
3
  class Role
4
+ include ::ActiveAttr::MassAssignmentSecurity
5
+ include ::ActiveAttr::Model
6
+
4
7
 
5
- attr_reader :section, :group_name, :group_id, :permissions
6
8
  # @!attribute [rw] section
7
- # @param [Osm::Section] section the section this role is related to (can only be set once)
9
+ # @param [Osm::Section] section the section this role is related to
8
10
  # @return [Osm::Section] the section this role related to
9
- # @!attribute [r] group_name
11
+ # @!attribute [rw] group_name
10
12
  # @return [String] the name of the group the section is in
11
- # @!attribute [r] group_id
13
+ # @!attribute [rw] group_id
12
14
  # @return [Fixnum] the group the section is in
13
- # @!attribute [r] permissions
15
+ # @!attribute [rw] permissions
14
16
  # @return [Hash] the permissions the user has in this role
15
17
 
16
- # Initialize a new ApiAccess
17
- # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
18
- def initialize(attributes={})
19
- raise ArgumentError, ':group_id must be nil or a Fixnum > 0' unless attributes[:group_id].nil? || (attributes[:group_id].is_a?(Fixnum) && attributes[:group_id] > 0)
20
- raise ArgumentError, ':group_name must be nil or a String' unless attributes[:group_name].nil? || attributes[:group_name].is_a?(String)
21
- raise ArgumentError, ':permissions must be nil or a Hash' unless attributes[:permissions].nil? || attributes[:permissions].is_a?(Hash)
18
+ attribute :section, :type => Object
19
+ attribute :group_name, :type => String
20
+ attribute :group_id, :type => Integer
21
+ attribute :permissions, :default => {}
22
+
23
+ attr_accessible :section, :group_name, :group_id, :permissions
24
+
22
25
 
23
- attributes.each { |k,v| instance_variable_set("@#{k}", v) }
26
+ validates_presence_of :section
27
+ validates_numericality_of :group_id, :only_integer=>true, :greater_than=>0
28
+ validates_presence_of :group_name
29
+ validates_presence_of :permissions, :unless => Proc.new { |a| a.permissions == {} }
24
30
 
25
- @name ||= ''
26
- @permissions ||= {}
31
+ validates :permissions, :hash => {:key_type => Symbol, :value_in => [10, 20, 100]}
32
+
33
+ validates_each :section do |record, attr, value|
34
+ unless value.nil?
35
+ record.errors.add(attr, 'must also be valid') unless value.valid?
36
+ end
27
37
  end
28
38
 
29
39
 
30
- # Initialize a new ApiAccess from api data
40
+ # @!method initialize
41
+ # Initialize a new Role
42
+ # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
43
+
44
+
45
+ # Initialize a new Role from api data
31
46
  # @param [Hash] data the hash of data provided by the API
32
47
  def self.from_api(data)
33
48
  attributes = {}
@@ -42,48 +57,44 @@ module Osm
42
57
 
43
58
  role = new(attributes.merge(:permissions => permissions))
44
59
  role.section = Osm::Section.from_api(data['sectionid'], data['sectionname'], ActiveSupport::JSON.decode(data['sectionConfig']), role)
45
- return role
46
- end
47
60
 
48
- def section=(section)
49
- raise ArgumentError, 'section must be an Osm::Section' unless section.is_a?(Osm::Section)
50
- @section = section if @section.nil?
61
+ return role
51
62
  end
52
63
 
53
64
  # Determine if this role has read access for the provided permission
54
65
  # @param [Symbol] key the permission being queried
55
66
  # @return [Boolean] if this role can read the passed permission
56
67
  def can_read?(key)
57
- return [10, 20, 100].include?(@permissions[key])
68
+ return [10, 20, 100].include?(permissions[key])
58
69
  end
59
70
 
60
71
  # Determine if this role has write access for the provided permission
61
72
  # @param [Symbol] key the permission being queried
62
73
  # @return [Boolean] if this role can write the passed permission
63
74
  def can_write?(key)
64
- return [20, 100].include?(@permissions[key])
75
+ return [20, 100].include?(permissions[key])
65
76
  end
66
77
 
67
78
  # Get section's long name in a consistent format
68
79
  # @return [String] e.g. "Scouts (1st Somewhere)"
69
80
  def long_name
70
- @group_name.blank? ? @section.name : "#{@section.name} (#{@group_name})"
81
+ group_name.blank? ? section.name : "#{section.name} (#{group_name})"
71
82
  end
72
83
 
73
84
  # Get section's full name in a consistent format
74
85
  # @return [String] e.g. "1st Somewhere Beavers"
75
86
  def full_name
76
- @group_name.blank? ? @section.name : "#{@group_name} #{@section.name}"
87
+ group_name.blank? ? section.name : "#{group_name} #{section.name}"
77
88
  end
78
89
 
79
90
  def <=>(another_role)
80
91
  begin
81
- compare_group_name = self.group_name <=> another_role.group_name
92
+ compare_group_name = group_name <=> another_role.group_name
82
93
  return compare_group_name unless compare_group_name == 0
83
94
 
84
- return 0 if self.section.type == another_role.section.type
95
+ return 0 if section.type == another_role.section.type
85
96
  [:beavers, :cubs, :scouts, :explorers, :waiting, :adults].each do |type|
86
- return -1 if self.section.type == type
97
+ return -1 if section.type == type
87
98
  return 1 if another_role.section.type == type
88
99
  end
89
100
  rescue NoMethodError
@@ -93,12 +104,30 @@ module Osm
93
104
 
94
105
  def ==(another_role)
95
106
  begin
96
- return self.section == another_role.section
107
+ return section == another_role.section
97
108
  rescue NoMethodError
98
109
  return false
99
110
  end
100
111
  end
101
112
 
102
- end
113
+ def inspect
114
+ attribute_descriptions = attributes.merge('section' => section.inspect_without_role(self))
115
+ return_inspect(attribute_descriptions)
116
+ end
117
+
118
+ def inspect_without_section(exclude_section)
119
+ attribute_descriptions = (section == exclude_section) ? attributes.merge('section' => 'SET') : attributes
120
+ return_inspect(attribute_descriptions)
121
+ end
122
+
123
+
124
+ private
125
+ def return_inspect(attribute_descriptions)
126
+ attribute_descriptions.sort.map { |key, value| "#{key}: #{key.eql?('section') ? value : value.inspect}" }.join(", ")
127
+ separator = " " unless attribute_descriptions.empty?
128
+ "#<#{self.class.name}#{separator}#{attribute_descriptions}>"
129
+ end
130
+
131
+ end # Class Role
103
132
 
104
- end
133
+ end # Module