osm 0.0.11 → 0.0.12
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.
- data/CHANGELOG.md +29 -0
- data/lib/osm.rb +10 -2
- data/lib/osm/activity.rb +196 -40
- data/lib/osm/api.rb +27 -30
- data/lib/osm/api_access.rb +26 -11
- data/lib/osm/due_badges.rb +36 -22
- data/lib/osm/evening.rb +71 -34
- data/lib/osm/event.rb +30 -11
- data/lib/osm/grouping.rb +22 -8
- data/lib/osm/member.rb +59 -36
- data/lib/osm/register_data.rb +58 -0
- data/lib/osm/register_field.rb +39 -0
- data/lib/osm/role.rb +26 -9
- data/lib/osm/section.rb +95 -33
- data/lib/osm/term.rb +23 -8
- data/spec/osm/activity_spec.rb +34 -7
- data/spec/osm/api_access_spec.rb +9 -9
- data/spec/osm/api_spec.rb +7 -8
- data/spec/osm/due_badges_spec.rb +2 -2
- data/spec/osm/evening_spec.rb +30 -25
- data/spec/osm/event_spec.rb +2 -2
- data/spec/osm/grouping_spec.rb +1 -1
- data/spec/osm/member_spec.rb +6 -6
- data/spec/osm/register_data_spec.rb +34 -0
- data/spec/osm/register_field_spec.rb +23 -0
- data/spec/osm/role_spec.rb +33 -30
- data/spec/osm/section_spec.rb +61 -99
- data/spec/osm/term_spec.rb +40 -77
- data/version.rb +1 -1
- metadata +16 -12
data/lib/osm/api_access.rb
CHANGED
@@ -10,18 +10,33 @@ module Osm
|
|
10
10
|
# @!attribute [r] permissions
|
11
11
|
# @return [Hash] the permissions assigned to this API by the user in OSM
|
12
12
|
|
13
|
-
# Initialize a new
|
14
|
-
# @param
|
15
|
-
def initialize(
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
# Initialize a new ApiAccess
|
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
|
+
raise ArgumentError, ':id must be a Fixnum > 0' unless (attributes[:id].is_a?(Fixnum) && attributes[:id] > 0)
|
17
|
+
raise ArgumentError, ':name must be a String' unless attributes[:name].is_a?(String)
|
18
|
+
raise ArgumentError, ':permissions must be a Hash' unless attributes[:permissions].is_a?(Hash)
|
19
|
+
|
20
|
+
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Initialize a new ApiAccess from api data
|
25
|
+
# @param [Hash] data the hash of data provided by the API
|
26
|
+
def self.from_api(data)
|
27
|
+
attributes = {}
|
28
|
+
attributes[:id] = data['apiid'].to_i
|
29
|
+
attributes[:name] = data['name']
|
30
|
+
attributes[:permissions] = data['permissions'].is_a?(Hash) ? data['permissions'] : {}
|
19
31
|
|
20
32
|
# Rubyfy permissions hash
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
attributes[:permissions].keys.each do |key|
|
34
|
+
attributes[:permissions][key] = attributes[:permissions][key].to_i
|
35
|
+
attributes[:permissions][(key.to_sym rescue key) || key] = attributes[:permissions].delete(key) # Symbolize key
|
24
36
|
end
|
37
|
+
attributes[:permissions].freeze
|
38
|
+
|
39
|
+
return new(attributes)
|
25
40
|
end
|
26
41
|
|
27
42
|
# Determine if this API has read access for the provided permission
|
@@ -44,6 +59,6 @@ module Osm
|
|
44
59
|
return @id == Osm::Api.api_id.to_i
|
45
60
|
end
|
46
61
|
|
47
|
-
end
|
62
|
+
end # Class
|
48
63
|
|
49
|
-
end
|
64
|
+
end # Module
|
data/lib/osm/due_badges.rb
CHANGED
@@ -10,44 +10,58 @@ module Osm
|
|
10
10
|
# @!attribute [r] totals
|
11
11
|
# @return [Hash] the total number of each badge which is due
|
12
12
|
|
13
|
-
# Initialize a new
|
14
|
-
# @param
|
15
|
-
def initialize(
|
13
|
+
# Initialize a new DueBadges
|
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
|
+
[:descriptions, :by_member, :totals].each do |attribute|
|
17
|
+
raise ArgumentError, ":#{attribute} must be a Hash" unless attributes[attribute].is_a?(Hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Initialize a new DueBadges from api data
|
25
|
+
# @param [Hash] data the hash of data provided by the API
|
26
|
+
def self.from_api(data)
|
16
27
|
data = {} unless data.is_a?(Hash)
|
28
|
+
attributes = {}
|
17
29
|
|
18
|
-
|
19
|
-
|
30
|
+
attributes[:pending] = data['pending'].is_a?(Hash) ? Osm::symbolize_hash(data['pending']) : {}
|
31
|
+
attributes[:descriptions] = data['description'].is_a?(Hash) ? Osm::symbolize_hash(data['description']) : {}
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
attributes[:pending].each_key do |key|
|
34
|
+
attributes[:pending][key].each_with_index do |item, index|
|
35
|
+
attributes[:pending][key][index] = item = Osm::symbolize_hash(item)
|
24
36
|
item[:sid] = item[:sid].to_i
|
25
37
|
item[:completed] = item[:completed].to_i
|
26
38
|
end
|
27
39
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
40
|
+
attributes[:descriptions].each_key do |key|
|
41
|
+
attributes[:descriptions][key] = Osm::symbolize_hash(attributes[:descriptions][key])
|
42
|
+
attributes[:descriptions][key][:section] = attributes[:descriptions][key][:section].to_sym
|
43
|
+
attributes[:descriptions][key][:type] = attributes[:descriptions][key][:type].to_sym
|
32
44
|
end
|
33
45
|
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
47
|
+
attributes[:by_member] = {}
|
48
|
+
attributes[:totals] = {}
|
49
|
+
attributes[:pending].each_key do |key|
|
50
|
+
attributes[:pending][key].each do |item|
|
39
51
|
name = "#{item[:firstname]} #{item[:lastname]}"
|
40
|
-
by_member[name] = [] if by_member[name].nil?
|
52
|
+
attributes[:by_member][name] = [] if attributes[:by_member][name].nil?
|
41
53
|
|
42
54
|
badge = {
|
43
55
|
:badge => key,
|
44
56
|
:extra_information => item[:extra]
|
45
57
|
}
|
46
|
-
by_member[name].push badge
|
47
|
-
|
48
|
-
|
58
|
+
attributes[:by_member][name].push badge
|
59
|
+
attributes[:totals][key] = {} if attributes[:totals][key].nil?
|
60
|
+
attributes[:totals][key][item[:extra]] = attributes[:totals][key][item[:extra]].to_i + 1
|
49
61
|
end
|
50
62
|
end
|
63
|
+
|
64
|
+
new(attributes)
|
51
65
|
end
|
52
66
|
|
53
67
|
# Check if there are no badges due
|
@@ -56,6 +70,6 @@ module Osm
|
|
56
70
|
return @by_member.empty?
|
57
71
|
end
|
58
72
|
|
59
|
-
end
|
73
|
+
end # Class
|
60
74
|
|
61
|
-
end
|
75
|
+
end # Module
|
data/lib/osm/evening.rb
CHANGED
@@ -6,7 +6,7 @@ module Osm
|
|
6
6
|
attr_reader :start_time, :end_time
|
7
7
|
# @!attribute [rw] evening_id
|
8
8
|
# @return [Fixnum] the id of the evening
|
9
|
-
# @!attribute [rw]
|
9
|
+
# @!attribute [rw] section_id
|
10
10
|
# @return [Fixnum] the section the evening belongs to
|
11
11
|
# @!attribute [rw] title
|
12
12
|
# @return [String] the title of the evening
|
@@ -23,35 +23,59 @@ module Osm
|
|
23
23
|
# @!attribute [rw] meeting_date
|
24
24
|
# @return [Date] the date of the evening
|
25
25
|
# @!attribute [rw] activities
|
26
|
-
# @return [Array<
|
26
|
+
# @return [Array<Activity>] list of activities being done during the evening
|
27
27
|
# @!attribute [rw] start_time
|
28
28
|
# @return [String] the start time (hh:mm)
|
29
29
|
# @!attribute [rw] end_time
|
30
30
|
# @return [String] the end time (hh:mm)
|
31
31
|
|
32
|
-
# Initialize a new
|
33
|
-
# @param
|
32
|
+
# Initialize a new Evening
|
33
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
34
|
+
def initialize(attributes={})
|
35
|
+
[:evening_id, :section_id].each do |attribute|
|
36
|
+
raise ArgumentError, ":#{attribute} must be nil or a Fixnum > 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] > 0)
|
37
|
+
end
|
38
|
+
[:title, :notes_for_parents, :games, :pre_notes, :post_notes, :leaders].each do |attribute|
|
39
|
+
raise ArgumentError, ":#{attribute} must be nil or a String" unless (attributes[attribute].nil? || attributes[attribute].is_a?(String))
|
40
|
+
end
|
41
|
+
raise ArgumentError, ':meeting_date must be a Date' unless attributes[:meeting_date].is_a?(Date)
|
42
|
+
raise ArgumentError, ':activities must be nil or an Array of Osm::Evening::Activity' unless (attributes[:activities].nil? || Osm::is_array_of?(attributes[:activities], Osm::Evening::Activity))
|
43
|
+
|
44
|
+
attributes.each { |k,v| send("#{k}=", v) }
|
45
|
+
|
46
|
+
@activities ||= []
|
47
|
+
@title ||= 'Unnamed meeting'
|
48
|
+
[:notes_for_parents, :games, :pre_notes, :post_notes, :leaders].each do |attribute|
|
49
|
+
instance_variable_set("@#{attribute}", '') if instance_variable_get("@#{attribute}").nil?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Initialize a new Evening from api data
|
55
|
+
# @param [Hash] data the hash of data provided by the API
|
34
56
|
# @param activities an array of hashes to generate the list of ProgrammeActivity objects
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
57
|
+
def self.from_api(data, activities)
|
58
|
+
attributes = {}
|
59
|
+
attributes[:evening_id] = Osm::to_i_or_nil(data['eveningid'])
|
60
|
+
attributes[:section_id] = Osm::to_i_or_nil(data['sectionid'])
|
61
|
+
attributes[:title] = data['title'] || 'Unnamed meeting'
|
62
|
+
attributes[:notes_for_parents] = data['notesforparents'] || ''
|
63
|
+
attributes[:games] = data['games'] || ''
|
64
|
+
attributes[:pre_notes] = data['prenotes'] || ''
|
65
|
+
attributes[:post_notes] = data['postnotes'] || ''
|
66
|
+
attributes[:leaders] = data['leaders'] || ''
|
67
|
+
attributes[:start_time] = data['starttime'].nil? ? nil : data['starttime'][0..4]
|
68
|
+
attributes[:end_time] = data['endtime'].nil? ? nil : data['endtime'][0..4]
|
69
|
+
attributes[:meeting_date] = Osm::parse_date(data['meetingdate'])
|
70
|
+
|
71
|
+
attributes[:activities] = Array.new
|
49
72
|
unless activities.nil?
|
50
73
|
activities.each do |item|
|
51
|
-
|
74
|
+
attributes[:activities].push Evening::Activity.from_api(item)
|
52
75
|
end
|
53
76
|
end
|
54
|
-
|
77
|
+
|
78
|
+
new(attributes)
|
55
79
|
end
|
56
80
|
|
57
81
|
# Custom setters for times
|
@@ -67,11 +91,11 @@ module Osm
|
|
67
91
|
|
68
92
|
# Get the evening's data for use with the API
|
69
93
|
# @return [Hash]
|
70
|
-
def
|
94
|
+
def to_api
|
71
95
|
{
|
72
96
|
'eveningid' => evening_id,
|
73
97
|
'sectionid' => section_id,
|
74
|
-
'meetingdate' => meeting_date.
|
98
|
+
'meetingdate' => meeting_date.strftime('%Y-%m-%d'),
|
75
99
|
'starttime' => start_time,
|
76
100
|
'endtime' => end_time,
|
77
101
|
'title' => title,
|
@@ -80,15 +104,15 @@ module Osm
|
|
80
104
|
'postnotes' => post_notes,
|
81
105
|
'games' => games,
|
82
106
|
'leaders' => leaders,
|
83
|
-
'activity' =>
|
107
|
+
'activity' => activities_for_to_api,
|
84
108
|
}
|
85
109
|
end
|
86
110
|
|
87
111
|
|
88
112
|
private
|
89
|
-
# Get the JSON for the
|
113
|
+
# Get the JSON for the activities to pass to the OSM API
|
90
114
|
# @return [String]
|
91
|
-
def
|
115
|
+
def activities_for_to_api
|
92
116
|
to_save = Array.new
|
93
117
|
@activities.each do |activity|
|
94
118
|
this_activity = {
|
@@ -101,8 +125,8 @@ module Osm
|
|
101
125
|
end
|
102
126
|
|
103
127
|
|
104
|
-
class
|
105
|
-
|
128
|
+
class Activity
|
129
|
+
|
106
130
|
attr_reader :activity_id, :title, :notes
|
107
131
|
# @!attribute [r] activity_id
|
108
132
|
# @return [Fixnum] the activity being done
|
@@ -111,14 +135,27 @@ module Osm
|
|
111
135
|
# @!attribute [r] notes
|
112
136
|
# @return [String] notes relevant to doing this activity on this evening
|
113
137
|
|
114
|
-
# Initialize a new
|
115
|
-
# @param
|
116
|
-
def initialize(
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
138
|
+
# Initialize a new Evening::Activity
|
139
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
140
|
+
def initialize(attributes={})
|
141
|
+
raise ArgumentError, ':activity_id must be a Fixnum > 0' unless (attributes[:activity_id].is_a?(Fixnum) && attributes[:activity_id] > 0)
|
142
|
+
raise ArgumentError, ':title must be nil or a String' unless (attributes[:title].nil? || attributes[:title].is_a?(String))
|
143
|
+
raise ArgumentError, ':notes must be nil or a String' unless (attributes[:notes].nil? || attributes[:notes].is_a?(String))
|
121
144
|
|
145
|
+
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
# Initialize a new Evening::Activity from api data
|
150
|
+
# @param [Hash] data the hash of data provided by the API
|
151
|
+
def self.from_api(data)
|
152
|
+
new({
|
153
|
+
:activity_id => Osm::to_i_or_nil(data['activityid']),
|
154
|
+
:title => data['title'],
|
155
|
+
:notes => data['notes'],
|
156
|
+
})
|
157
|
+
end
|
158
|
+
|
122
159
|
end
|
123
160
|
|
124
161
|
|
data/lib/osm/event.rb
CHANGED
@@ -20,17 +20,36 @@ module Osm
|
|
20
20
|
# @!attribute [r] notes
|
21
21
|
# @return [String] notes about the event
|
22
22
|
|
23
|
-
# Initialize a new Event
|
24
|
-
# @param
|
25
|
-
def initialize(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
# Initialize a new Event
|
24
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
25
|
+
def initialize(attributes={})
|
26
|
+
[:id, :section_id].each do |attribute|
|
27
|
+
raise ArgumentError, ":#{attribute} must be nil or a Fixnum > 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] > 0)
|
28
|
+
end
|
29
|
+
raise ArgumentError, ':name must be a String' unless attributes[:name].is_a?(String)
|
30
|
+
raise ArgumentError, ':start must be nil or a DateTime' unless attributes[:start].nil? || attributes[:start].is_a?(DateTime)
|
31
|
+
raise ArgumentError, ':end must be nil or a DateTime' unless attributes[:end].nil? || attributes[:end].is_a?(DateTime)
|
32
|
+
[:cost, :location, :notes].each do |attribute|
|
33
|
+
raise ArgumentError, ":#{attribute} must be nil or a String" unless attributes[attribute].nil? || attributes[attribute].is_a?(String)
|
34
|
+
end
|
35
|
+
|
36
|
+
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Initialize a new Event from api data
|
41
|
+
# @param [Hash] data the hash of data provided by the API
|
42
|
+
def self.from_api(data)
|
43
|
+
new({
|
44
|
+
:id => Osm::to_i_or_nil(data['eventid']),
|
45
|
+
:section_id => Osm::to_i_or_nil(data['sectionid']),
|
46
|
+
:name => data['name'],
|
47
|
+
:start => Osm::make_datetime(data['startdate'], data['starttime']),
|
48
|
+
:end => Osm::make_datetime(data['enddate'], data['endtime']),
|
49
|
+
:cost => data['cost'],
|
50
|
+
:location => data['location'],
|
51
|
+
:notes => data['notes'],
|
52
|
+
})
|
34
53
|
end
|
35
54
|
|
36
55
|
end
|
data/lib/osm/grouping.rb
CHANGED
@@ -7,18 +7,32 @@ module Osm
|
|
7
7
|
# @return [Fixnum] the id for grouping
|
8
8
|
# @!attribute [r] name
|
9
9
|
# @return [String] the name of the grouping
|
10
|
-
# @!attribute [r]
|
10
|
+
# @!attribute [r] active
|
11
11
|
# @return [Boolean] wether the grouping is active
|
12
12
|
# @!attribute [r] points
|
13
13
|
# @return [Fixnum] the points awarded to the grouping
|
14
14
|
|
15
|
-
# Initialize a new Grouping
|
16
|
-
# @param
|
17
|
-
def initialize(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
# Initialize a new Grouping
|
16
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
17
|
+
def initialize(attributes={})
|
18
|
+
raise ArgumentError, ':id must be a Fixnum > 0' unless (attributes[:id].is_a?(Fixnum) && attributes[:id] > 0)
|
19
|
+
raise ArgumentError, ':name must be a String' unless attributes[:name].is_a?(String)
|
20
|
+
raise ArgumentError, ':active must be nil or a Boolean' unless attributes[:active].nil? || [true, false].include?(attributes[:active])
|
21
|
+
raise ArgumentError, ':points must be nil or a Fixnum >= 0' unless attributes[:points].nil? || (attributes[:points].is_a?(Fixnum) && attributes[:points] >= 0)
|
22
|
+
|
23
|
+
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# Initialize a new Grouping from api data
|
28
|
+
# @param [Hash] data the hash of data provided by the API
|
29
|
+
def self.from_api(data)
|
30
|
+
new({
|
31
|
+
:id => Osm::to_i_or_nil(data['patrolid']),
|
32
|
+
:name => data['name'],
|
33
|
+
:active => (data['active'] == 1),
|
34
|
+
:points => Osm::to_i_or_nil(data['points']),
|
35
|
+
})
|
22
36
|
end
|
23
37
|
|
24
38
|
end
|
data/lib/osm/member.rb
CHANGED
@@ -2,7 +2,7 @@ module Osm
|
|
2
2
|
|
3
3
|
class Member
|
4
4
|
|
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, :
|
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
6
|
# @!attribute [r] id
|
7
7
|
# @return [Fixnum] the id for the member
|
8
8
|
# @!attribute [r] section_id
|
@@ -37,7 +37,7 @@ module Osm
|
|
37
37
|
# @return [Date] the member's date of birth
|
38
38
|
# @!attribute [r] started
|
39
39
|
# @return [Date] when the member started Scouting
|
40
|
-
# @!attribute [r]
|
40
|
+
# @!attribute [r] joining_in_years
|
41
41
|
# @return [Fixnum] ?
|
42
42
|
# @!attribute [r] parents
|
43
43
|
# @return [String] the member's parent's names
|
@@ -61,43 +61,66 @@ module Osm
|
|
61
61
|
# @return [Date] when the member joined the section
|
62
62
|
# @!attribute [r] age
|
63
63
|
# @return [String] the member's current age (yy/mm)
|
64
|
-
# @!attribute [r]
|
64
|
+
# @!attribute [r] joining_years
|
65
65
|
# @return [Fixnum] how many years the member has been in Scouting
|
66
66
|
|
67
67
|
|
68
|
-
# Initialize a new Member
|
69
|
-
# @param
|
70
|
-
def initialize(
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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_id].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
|
+
[:joined_years, :grouping_leader].each do |attribute|
|
75
|
+
raise ArgumentError, ":#{attribute} must be nil or a Fixnum >= 0" unless attributes[attribute].nil? || (attributes[attribute].is_a?(Fixnum) && attributes[attribute] >= 0)
|
76
|
+
end
|
77
|
+
raise ArgumentError, ':joining_in_years must be nil or a Fixnum' unless attributes[:joining_in_years].nil? || attributes[:joining_in_years].is_a?(Fixnum)
|
78
|
+
[: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|
|
79
|
+
raise ArgumentError, ":#{attribute} must be nil or a String" unless attributes[attribute].nil? || attributes[attribute].is_a?(String)
|
80
|
+
end
|
81
|
+
[:date_of_birth, :started, :joined].each do |attribute|
|
82
|
+
raise ArgumentError, ":#{attribute} must be nil or a Date" unless attributes[attribute].nil? || attributes[attribute].is_a?(Date)
|
83
|
+
end
|
84
|
+
|
85
|
+
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
# Initialize a new Member from api data
|
90
|
+
# @param [Hash] data the hash of data provided by the API
|
91
|
+
def self.from_api(data)
|
92
|
+
new({
|
93
|
+
:id => Osm::to_i_or_nil(data['scoutid']),
|
94
|
+
:section_id => Osm::to_i_or_nil(data['sectionidO']),
|
95
|
+
:type => data['type'],
|
96
|
+
:first_name => data['firstname'],
|
97
|
+
:last_name => data['lastname'],
|
98
|
+
:email1 => data['email1'],
|
99
|
+
:email2 => data['email2'],
|
100
|
+
:email3 => data['email3'],
|
101
|
+
:email4 => data['email4'],
|
102
|
+
:phone1 => data['phone1'],
|
103
|
+
:phone2 => data['phone2'],
|
104
|
+
:phone3 => data['phone3'],
|
105
|
+
:phone4 => data['phone4'],
|
106
|
+
:address => data['address'],
|
107
|
+
:address2 => data['address2'],
|
108
|
+
:date_of_birth => Osm::parse_date(data['dob']),
|
109
|
+
:started => Osm::parse_date(data['started']),
|
110
|
+
:joining_in_years => data['joining_in_yrs'].to_i,
|
111
|
+
:parents => data['parents'],
|
112
|
+
:notes => data['notes'],
|
113
|
+
:medical => data['medical'],
|
114
|
+
:religion => data['religion'],
|
115
|
+
:school => data['school'],
|
116
|
+
:ethnicity => data['ethnicity'],
|
117
|
+
:subs => data['subs'],
|
118
|
+
:grouping_id => Osm::to_i_or_nil(data['patrolidO']),
|
119
|
+
:grouping_leader => data['patrolleaderO'],
|
120
|
+
:joined => Osm::parse_date(data['joined']),
|
121
|
+
:age => data['age'],
|
122
|
+
:joined_years => data['yrs'].to_i,
|
123
|
+
})
|
101
124
|
end
|
102
125
|
|
103
126
|
# Get the years element of this scout's age
|