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.
- data/CHANGELOG.md +21 -0
- data/README.md +4 -0
- data/lib/array_of_validator.rb +15 -0
- data/lib/hash_validator.rb +24 -0
- data/lib/osm.rb +11 -14
- data/lib/osm/activity.rb +152 -103
- data/lib/osm/api.rb +3 -2
- data/lib/osm/api_access.rb +23 -16
- data/lib/osm/due_badges.rb +53 -24
- data/lib/osm/evening.rb +58 -56
- data/lib/osm/event.rb +23 -19
- data/lib/osm/grouping.rb +23 -16
- data/lib/osm/member.rb +86 -54
- data/lib/osm/register_data.rb +34 -25
- data/lib/osm/register_field.rb +19 -16
- data/lib/osm/role.rb +59 -30
- data/lib/osm/section.rb +93 -60
- data/lib/osm/term.rb +36 -28
- data/osm.gemspec +2 -0
- data/spec/osm/activity_spec.rb +2 -0
- data/spec/osm/api_access_spec.rb +3 -2
- data/spec/osm/api_spec.rb +10 -5
- data/spec/osm/due_badges_spec.rb +1 -0
- data/spec/osm/evening_spec.rb +5 -20
- data/spec/osm/event_spec.rb +2 -1
- data/spec/osm/grouping_spec.rb +1 -0
- data/spec/osm/member_spec.rb +1 -0
- data/spec/osm/register_data_spec.rb +1 -0
- data/spec/osm/register_field_spec.rb +1 -0
- data/spec/osm/role_spec.rb +6 -2
- data/spec/osm/section_spec.rb +2 -0
- data/spec/osm/term_spec.rb +26 -25
- data/spec/spec_helper.rb +2 -0
- data/version.rb +1 -1
- metadata +36 -12
data/lib/osm/api.rb
CHANGED
@@ -529,6 +529,7 @@ module Osm
|
|
529
529
|
# @!macro options_api_data
|
530
530
|
# @return [Boolean] if the operation suceeded or not
|
531
531
|
def update_evening(evening, api_data={})
|
532
|
+
raise ArgumentIsInvalid, 'evening is invalid' unless evening.valid?
|
532
533
|
response = perform_query("programme.php?action=editEvening", api_data.merge(evening.to_api))
|
533
534
|
|
534
535
|
# The cached programmes for the section will be out of date - remove them
|
@@ -679,6 +680,6 @@ module Osm
|
|
679
680
|
return term.nil? ? Osm::find_current_term_id(self, id_for_section(section), api_data) : id_for(Osm::Term, term, 'term')
|
680
681
|
end
|
681
682
|
|
682
|
-
end
|
683
|
+
end # Class Api
|
683
684
|
|
684
|
-
end
|
685
|
+
end # Module
|
data/lib/osm/api_access.rb
CHANGED
@@ -1,24 +1,31 @@
|
|
1
1
|
module Osm
|
2
2
|
|
3
3
|
class ApiAccess
|
4
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
+
include ::ActiveAttr::Model
|
4
6
|
|
5
|
-
|
6
|
-
# @!attribute [r] id
|
7
|
+
# @!attribute [rw] id
|
7
8
|
# @return [Fixnum] the id for the API
|
8
|
-
# @!attribute [
|
9
|
+
# @!attribute [rw] name
|
9
10
|
# @return [String] the name of the API
|
10
|
-
# @!attribute [
|
11
|
+
# @!attribute [rw] permissions
|
11
12
|
# @return [Hash] the permissions assigned to this API by the user in OSM
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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)
|
14
|
+
attribute :id, :type => Integer
|
15
|
+
attribute :name, :type => String
|
16
|
+
attribute :permissions, :default => {}
|
19
17
|
|
20
|
-
|
21
|
-
|
18
|
+
attr_accessible :id, :name, :permissions
|
19
|
+
|
20
|
+
validates_numericality_of :id, :only_integer=>true, :greater_than=>0
|
21
|
+
validates_presence_of :name
|
22
|
+
|
23
|
+
validates :permissions, :hash => {:key_type => Symbol, :value_in => [10, 20]}
|
24
|
+
|
25
|
+
|
26
|
+
# @!method initialize
|
27
|
+
# Initialize a new Term
|
28
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
22
29
|
|
23
30
|
|
24
31
|
# Initialize a new ApiAccess from api data
|
@@ -43,22 +50,22 @@ module Osm
|
|
43
50
|
# @param [Symbol] key the permission being queried
|
44
51
|
# @return [Boolean] if this API can read the passed permission
|
45
52
|
def can_read?(key)
|
46
|
-
return [20, 10].include?(
|
53
|
+
return [20, 10].include?(permissions[key])
|
47
54
|
end
|
48
55
|
|
49
56
|
# Determine if this API has write access for the provided permission
|
50
57
|
# @param [Symbol] key the permission being queried
|
51
58
|
# @return [Boolean] if this API can write the passed permission
|
52
59
|
def can_write?(key)
|
53
|
-
return [20].include?(
|
60
|
+
return [20].include?(permissions[key])
|
54
61
|
end
|
55
62
|
|
56
63
|
# Determine if this API is the API being used to make requests
|
57
64
|
# @return [Boolean] if this is the API being used
|
58
65
|
def our_api?
|
59
|
-
return
|
66
|
+
return id == Osm::Api.api_id.to_i
|
60
67
|
end
|
61
68
|
|
62
|
-
end # Class
|
69
|
+
end # Class ApiAccess
|
63
70
|
|
64
71
|
end # Module
|
data/lib/osm/due_badges.rb
CHANGED
@@ -1,38 +1,51 @@
|
|
1
1
|
module Osm
|
2
2
|
|
3
3
|
class DueBadges
|
4
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
+
include ::ActiveAttr::Model
|
4
6
|
|
5
|
-
|
6
|
-
# @!attribute [r] descriptions
|
7
|
+
# @!attribute [rw] descriptions
|
7
8
|
# @return [Hash] descriptions for each of the badges
|
8
|
-
# @!attribute [
|
9
|
+
# @!attribute [rw] by_member
|
9
10
|
# @return [Hash] the due badges grouped by member
|
10
|
-
# @!attribute [r] totals
|
11
|
-
# @return [Hash] the total number of each badge which is due
|
12
|
-
|
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, exclude total as this is calculated for you)
|
15
|
-
def initialize(attributes={})
|
16
|
-
[:descriptions, :by_member].each do |attribute|
|
17
|
-
raise ArgumentError, ":#{attribute} must be a Hash" unless attributes[attribute].is_a?(Hash)
|
18
|
-
end
|
19
11
|
|
20
|
-
|
12
|
+
attribute :descriptions, :default => {}
|
13
|
+
attribute :by_member, :default => {}
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
attr_accessible :descriptions, :by_member
|
16
|
+
|
17
|
+
validates_each :descriptions do |record, attr, value|
|
18
|
+
record.errors.add(attr, 'must be a Hash') unless value.is_a?(Hash)
|
19
|
+
value.each do |k, v|
|
20
|
+
record.errors.add(attr, 'keys must be Symbols') unless k.is_a?(Symbol)
|
21
|
+
record.errors.add(attr, 'values must be Hashes') unless v.is_a?(Hash)
|
22
|
+
[:name, :section, :type, :badge].each do |key|
|
23
|
+
record.errors.add(attr, "values must include the key #{key}") unless v.keys.include?(key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
validates_each :by_member do |record, attr, value|
|
29
|
+
record.errors.add(attr, 'must be a Hash') unless value.is_a?(Hash)
|
30
|
+
value.each do |k, v|
|
31
|
+
record.errors.add(attr, 'keys must be String') unless k.is_a?(String)
|
32
|
+
record.errors.add(attr, 'values must be Arrays') unless v.is_a?(Array)
|
33
|
+
v.each do |vv|
|
34
|
+
record.errors.add(attr, 'internal values must be Hashes') unless vv.is_a?(Hash)
|
35
|
+
record.errors.add(attr, 'internal values must include the key :badge') unless vv.keys.include?(:badge)
|
36
|
+
record.errors.add(attr, 'internal values :badge value must be a Symbol') unless vv[:badge].is_a?(Symbol)
|
37
|
+
record.errors.add(attr, 'internal values must include the key :extra_information') unless vv.keys.include?(:extra_information)
|
38
|
+
record.errors.add(attr, 'internal values :extra_information value must be a String') unless vv[:extra_information].is_a?(String)
|
31
39
|
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
35
43
|
|
44
|
+
# @!method initialize
|
45
|
+
# Initialize a new Term
|
46
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
47
|
+
|
48
|
+
|
36
49
|
# Initialize a new DueBadges from api data
|
37
50
|
# @param [Hash] data the hash of data provided by the API
|
38
51
|
def self.from_api(data)
|
@@ -75,9 +88,25 @@ module Osm
|
|
75
88
|
# Check if there are no badges due
|
76
89
|
# @return [Boolean]
|
77
90
|
def empty?
|
78
|
-
return
|
91
|
+
return by_member.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
# Calculate the total number of badges needed
|
95
|
+
# @return [Hash] the total number of each badge which is due
|
96
|
+
def totals(attributes={})
|
97
|
+
totals = {}
|
98
|
+
by_member.keys.each do |member_name|
|
99
|
+
by_member[member_name].each do |badge_record|
|
100
|
+
badge_symbol = badge_record[:badge]
|
101
|
+
badge_extra = badge_record[:extra_information]
|
102
|
+
totals[badge_record[:badge]] ||= {}
|
103
|
+
totals[badge_symbol][badge_extra] ||= 0
|
104
|
+
totals[badge_symbol][badge_extra] += 1
|
105
|
+
end
|
106
|
+
end
|
107
|
+
return totals
|
79
108
|
end
|
80
109
|
|
81
|
-
end # Class
|
110
|
+
end # Class DueBadges
|
82
111
|
|
83
112
|
end # Module
|
data/lib/osm/evening.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Osm
|
2
2
|
|
3
3
|
class Evening
|
4
|
+
class Activity; end # Ensure the constant exists for the validators
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
7
|
+
include ::ActiveAttr::Model
|
8
|
+
|
9
|
+
# @!attribute [rw] id
|
8
10
|
# @return [Fixnum] the id of the evening
|
9
11
|
# @!attribute [rw] section_id
|
10
12
|
# @return [Fixnum] the section the evening belongs to
|
@@ -26,29 +28,36 @@ module Osm
|
|
26
28
|
# @return [Array<Activity>] list of activities being done during the evening
|
27
29
|
# @!attribute [rw] start_time
|
28
30
|
# @return [String] the start time (hh:mm)
|
29
|
-
# @!attribute [rw]
|
31
|
+
# @!attribute [rw] finish_time
|
30
32
|
# @return [String] the end time (hh:mm)
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
attribute :id, :type => Integer
|
35
|
+
attribute :section_id, :type => Integer
|
36
|
+
attribute :title, :type => String, :default => 'Unnamed meeting'
|
37
|
+
attribute :notes_for_parents, :type => String, :default => ''
|
38
|
+
attribute :games, :type => String, :default => ''
|
39
|
+
attribute :pre_notes, :type => String, :default => ''
|
40
|
+
attribute :post_notes, :type => String, :default => ''
|
41
|
+
attribute :leaders, :type => String, :default => ''
|
42
|
+
attribute :meeting_date, :type => Date
|
43
|
+
attribute :start_time, :type => String
|
44
|
+
attribute :finish_time, :type => String
|
45
|
+
attribute :activities, :default => []
|
43
46
|
|
44
|
-
|
47
|
+
attr_accessible :id, :section_id, :title, :notes_for_parents, :games, :pre_notes, :post_notes, :leaders, :meeting_date, :activities, :start_time, :finish_time
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
validates_numericality_of :id, :only_integer=>true, :greater_than=>0
|
50
|
+
validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
|
51
|
+
validates_presence_of :title
|
52
|
+
validates_presence_of :meeting_date
|
53
|
+
validates_format_of :start_time, :with => Osm::OSM_TIME_REGEX, :message => 'is not in the correct format (HH:MM)', :allow_blank => true
|
54
|
+
validates_format_of :finish_time, :with => Osm::OSM_TIME_REGEX, :message => 'is not in the correct format (HH:MM)', :allow_blank => true
|
55
|
+
|
56
|
+
validates :activities, :array_of => {:item_type => Osm::Evening::Activity, :item_valid => true}
|
57
|
+
|
58
|
+
# @!method initialize
|
59
|
+
# Initialize a new Evening
|
60
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
52
61
|
|
53
62
|
|
54
63
|
# Initialize a new Evening from api data
|
@@ -56,7 +65,7 @@ module Osm
|
|
56
65
|
# @param activities an array of hashes to generate the list of ProgrammeActivity objects
|
57
66
|
def self.from_api(data, activities)
|
58
67
|
attributes = {}
|
59
|
-
attributes[:
|
68
|
+
attributes[:id] = Osm::to_i_or_nil(data['eveningid'])
|
60
69
|
attributes[:section_id] = Osm::to_i_or_nil(data['sectionid'])
|
61
70
|
attributes[:title] = data['title'] || 'Unnamed meeting'
|
62
71
|
attributes[:notes_for_parents] = data['notesforparents'] || ''
|
@@ -65,7 +74,7 @@ module Osm
|
|
65
74
|
attributes[:post_notes] = data['postnotes'] || ''
|
66
75
|
attributes[:leaders] = data['leaders'] || ''
|
67
76
|
attributes[:start_time] = data['starttime'].nil? ? nil : data['starttime'][0..4]
|
68
|
-
attributes[:
|
77
|
+
attributes[:finish_time] = data['endtime'].nil? ? nil : data['endtime'][0..4]
|
69
78
|
attributes[:meeting_date] = Osm::parse_date(data['meetingdate'])
|
70
79
|
|
71
80
|
attributes[:activities] = Array.new
|
@@ -78,26 +87,15 @@ module Osm
|
|
78
87
|
new(attributes)
|
79
88
|
end
|
80
89
|
|
81
|
-
# Custom setters for times
|
82
|
-
[:start, :end].each do |attribute|
|
83
|
-
define_method "#{attribute}_time=" do |value|
|
84
|
-
unless value.nil?
|
85
|
-
value = value.strftime('%H:%M') unless value.is_a?(String)
|
86
|
-
raise ArgumentError, 'invalid time' unless /\A(?:[0-1][0-9]|2[0-3]):[0-5][0-9]\Z/.match(value)
|
87
|
-
end
|
88
|
-
instance_variable_set("@#{attribute}_time", value)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
90
|
# Get the evening's data for use with the API
|
93
91
|
# @return [Hash]
|
94
92
|
def to_api
|
95
93
|
{
|
96
|
-
'eveningid' =>
|
94
|
+
'eveningid' => id,
|
97
95
|
'sectionid' => section_id,
|
98
96
|
'meetingdate' => meeting_date.strftime(Osm::OSM_DATE_FORMAT),
|
99
97
|
'starttime' => start_time,
|
100
|
-
'endtime' =>
|
98
|
+
'endtime' => finish_time,
|
101
99
|
'title' => title,
|
102
100
|
'notesforparents' => notes_for_parents,
|
103
101
|
'prenotes' => pre_notes,
|
@@ -114,7 +112,7 @@ module Osm
|
|
114
112
|
# @return [String]
|
115
113
|
def activities_for_to_api
|
116
114
|
to_save = Array.new
|
117
|
-
|
115
|
+
activities.each do |activity|
|
118
116
|
this_activity = {
|
119
117
|
'activityid' => activity.activity_id,
|
120
118
|
'notes' => activity.notes,
|
@@ -126,26 +124,31 @@ module Osm
|
|
126
124
|
|
127
125
|
|
128
126
|
class Activity
|
127
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
128
|
+
include ::ActiveAttr::Model
|
129
129
|
|
130
|
-
|
131
|
-
# @!attribute [r] activity_id
|
130
|
+
# @!attribute [rw] activity_id
|
132
131
|
# @return [Fixnum] the activity being done
|
133
|
-
# @!attribute [
|
132
|
+
# @!attribute [rw] title
|
134
133
|
# @return [String] the activity's title
|
135
|
-
# @!attribute [
|
134
|
+
# @!attribute [rw] notes
|
136
135
|
# @return [String] notes relevant to doing this activity on this evening
|
137
|
-
|
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))
|
144
|
-
|
145
|
-
attributes.each { |k,v| instance_variable_set("@#{k}", v) }
|
146
|
-
end
|
147
136
|
|
137
|
+
attribute :activity_id, :type => Integer
|
138
|
+
attribute :title, :type => String
|
139
|
+
attribute :notes, :type => String, :default => ''
|
140
|
+
|
141
|
+
attr_accessible :activity_id, :title, :notes
|
142
|
+
|
143
|
+
validates_numericality_of :activity_id, :only_integer=>true, :greater_than=>0
|
144
|
+
validates_presence_of :title
|
148
145
|
|
146
|
+
|
147
|
+
# @!method initialize
|
148
|
+
# Initialize a new Evening::Activity
|
149
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
150
|
+
|
151
|
+
|
149
152
|
# Initialize a new Evening::Activity from api data
|
150
153
|
# @param [Hash] data the hash of data provided by the API
|
151
154
|
def self.from_api(data)
|
@@ -156,9 +159,8 @@ module Osm
|
|
156
159
|
})
|
157
160
|
end
|
158
161
|
|
159
|
-
end
|
160
|
-
|
162
|
+
end # Class Evening::Activity
|
161
163
|
|
162
|
-
end
|
164
|
+
end # Class Evening
|
163
165
|
|
164
|
-
end
|
166
|
+
end # Module
|
data/lib/osm/event.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Osm
|
2
2
|
|
3
3
|
class Event
|
4
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
+
include ::ActiveAttr::Model
|
4
6
|
|
5
|
-
attr_reader :id, :section_id, :name, :start, :end, :cost, :location, :notes
|
6
7
|
# @!attribute [r] id
|
7
8
|
# @return [Fixnum] the id for the event
|
8
9
|
# @!attribute [r] section_id
|
@@ -11,7 +12,7 @@ module Osm
|
|
11
12
|
# @return [String] the name of the event
|
12
13
|
# @!attribute [r] start
|
13
14
|
# @return [DateTime] when the event starts
|
14
|
-
# @!attribute [r]
|
15
|
+
# @!attribute [r] finish
|
15
16
|
# @return [DateTime] when the event ends
|
16
17
|
# @!attribute [r] cost
|
17
18
|
# @return [String] the cost of the event
|
@@ -20,22 +21,25 @@ module Osm
|
|
20
21
|
# @!attribute [r] notes
|
21
22
|
# @return [String] notes about the event
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
attribute :id, :type => Integer
|
25
|
+
attribute :section_id, :type => Integer
|
26
|
+
attribute :name, :type => String
|
27
|
+
attribute :start, :type => DateTime
|
28
|
+
attribute :finish, :type => DateTime
|
29
|
+
attribute :cost, :type => String, :default => ''
|
30
|
+
attribute :location, :type => String, :default => ''
|
31
|
+
attribute :notes, :type => String, :default => ''
|
32
|
+
|
33
|
+
attr_accessible :id, :section_id, :name, :start, :finish, :cost, :location, :notes
|
34
|
+
|
35
|
+
validates_numericality_of :id, :only_integer=>true, :greater_than=>0
|
36
|
+
validates_numericality_of :section_id, :only_integer=>true, :greater_than=>0
|
37
|
+
validates_presence_of :name
|
38
|
+
|
38
39
|
|
40
|
+
# @!method initialize
|
41
|
+
# Initialize a new Term
|
42
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
39
43
|
|
40
44
|
# Initialize a new Event from api data
|
41
45
|
# @param [Hash] data the hash of data provided by the API
|
@@ -52,6 +56,6 @@ module Osm
|
|
52
56
|
})
|
53
57
|
end
|
54
58
|
|
55
|
-
end
|
59
|
+
end # Class Event
|
56
60
|
|
57
|
-
end
|
61
|
+
end # Module
|
data/lib/osm/grouping.rb
CHANGED
@@ -1,27 +1,34 @@
|
|
1
1
|
module Osm
|
2
2
|
|
3
3
|
class Grouping
|
4
|
+
include ::ActiveAttr::MassAssignmentSecurity
|
5
|
+
include ::ActiveAttr::Model
|
4
6
|
|
5
|
-
|
6
|
-
# @!attribute [r] id
|
7
|
+
# @!attribute [rw] id
|
7
8
|
# @return [Fixnum] the id for grouping
|
8
|
-
# @!attribute [
|
9
|
+
# @!attribute [rw] name
|
9
10
|
# @return [String] the name of the grouping
|
10
|
-
# @!attribute [
|
11
|
+
# @!attribute [rw] active
|
11
12
|
# @return [Boolean] wether the grouping is active
|
12
|
-
# @!attribute [
|
13
|
+
# @!attribute [rw] points
|
13
14
|
# @return [Fixnum] the points awarded to the grouping
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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)
|
16
|
+
attribute :id, :type => Integer
|
17
|
+
attribute :name, :type => String
|
18
|
+
attribute :active, :type => Boolean
|
19
|
+
attribute :points, :type => Integer
|
22
20
|
|
23
|
-
|
24
|
-
|
21
|
+
attr_accessible :id, :name, :active, :points
|
22
|
+
|
23
|
+
validates_numericality_of :id, :only_integer=>true, :greater_than_or_equal_to=>-2
|
24
|
+
validates_presence_of :name
|
25
|
+
validates_numericality_of :points, :only_integer=>true
|
26
|
+
validates_presence_of :active
|
27
|
+
|
28
|
+
|
29
|
+
# @!method initialize
|
30
|
+
# Initialize a new Term
|
31
|
+
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
25
32
|
|
26
33
|
|
27
34
|
# Initialize a new Grouping from api data
|
@@ -35,6 +42,6 @@ module Osm
|
|
35
42
|
})
|
36
43
|
end
|
37
44
|
|
38
|
-
end
|
45
|
+
end # Class Grouping
|
39
46
|
|
40
|
-
end
|
47
|
+
end # Module
|