Class: Osm::Grouping
Instance Attribute Summary collapse
-
#active ⇒ Boolean
Whether the grouping is active.
-
#id ⇒ Fixnum
The id for grouping.
-
#name ⇒ String
The name of the grouping.
-
#points ⇒ Fixnum
The points awarded to the grouping.
-
#section_id ⇒ Fixnum
The id for the section this grouping belongs to.
Class Method Summary collapse
-
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Grouping>?
Get the groupings that a section has.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Grouping based on section_id then name.
-
#initialize ⇒ Object
constructor
Initialize a new Term.
-
#update(api) ⇒ Boolan
Update the grouping in OSM.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Term
|
# File 'lib/osm/grouping.rb', line 67
|
Instance Attribute Details
#active ⇒ Boolean
Returns whether the grouping is active.
16 |
# File 'lib/osm/grouping.rb', line 16 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id for grouping.
16 |
# File 'lib/osm/grouping.rb', line 16 attribute :id, :type => Integer |
#name ⇒ String
Returns the name of the grouping.
16 |
# File 'lib/osm/grouping.rb', line 16 attribute :id, :type => Integer |
#points ⇒ Fixnum
Returns the points awarded to the grouping.
16 |
# File 'lib/osm/grouping.rb', line 16 attribute :id, :type => Integer |
#section_id ⇒ Fixnum
Returns the id for the section this grouping belongs to.
16 |
# File 'lib/osm/grouping.rb', line 16 attribute :id, :type => Integer |
Class Method Details
.get_for_section(api, section, options = {}) ⇒ Array<Osm::Grouping>?
Get the groupings that a section has
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osm/grouping.rb', line 38 def self.get_for_section(api, section, ={}) section_id = section.to_i require_ability_to(api, :read, :member, section_id) cache_key = ['groupings', section_id] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = api.perform_query("users.php?action=getPatrols§ionid=#{section_id}") result = Array.new if data.is_a?(Hash) && data['patrols'].is_a?(Array) data['patrols'].each do |item| result.push Osm::Grouping.new({ :id => Osm::to_i_or_nil(item['patrolid']), :section_id => section_id, :name => item['name'], :active => (item['active'] == 1), :points => Osm::to_i_or_nil(item['points']), }) end cache_write(api, cache_key, result) end return result end |
Instance Method Details
#<=>(another) ⇒ Object
Compare Grouping based on section_id then name
110 111 112 113 114 |
# File 'lib/osm/grouping.rb', line 110 def <=>(another) result = self.section_id <=> another.try(:section_id) result = self.name <=> another.try(:name) if result == 0 return result end |
#update(api) ⇒ Boolan
Update the grouping in OSM
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 101 102 103 104 105 106 107 |
# File 'lib/osm/grouping.rb', line 76 def update(api) raise Osm::ObjectIsInvalid, 'grouping is invalid' unless valid? require_ability_to(api, :read, :member, section_id) to_update = changed_attributes result = true if to_update.include?('name') || to_update.include?('active') data = api.perform_query("users.php?action=editPatrol§ionid=#{section_id}", { 'patrolid' => self.id, 'name' => name, 'active' => active, }) result &= data.nil? end if to_update.include?('points') data = api.perform_query("users.php?action=updatePatrolPoints§ionid=#{section_id}", { 'patrolid' => self.id, 'points' => points, }) result &= (data == {}) end if result reset_changed_attributes # The cached groupings for the section will be out of date - remove them Osm::Model.cache_delete(api, ['groupings', section_id]) end return result end |