Class: Osm::Grouping

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/grouping.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

configure, #to_i

Constructor Details

#initializeObject

Initialize a new Term

Parameters:

  • attributes (Hash)

    the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)



# File 'lib/osm/grouping.rb', line 62

Instance Attribute Details

#activeBoolean

Returns wether the grouping is active.

Returns:

  • (Boolean)

    wether the grouping is active



16
# File 'lib/osm/grouping.rb', line 16

attribute :id, :type => Integer

#idFixnum

Returns the id for grouping.

Returns:

  • (Fixnum)

    the id for grouping



16
# File 'lib/osm/grouping.rb', line 16

attribute :id, :type => Integer

#nameString

Returns the name of the grouping.

Returns:

  • (String)

    the name of the grouping



16
# File 'lib/osm/grouping.rb', line 16

attribute :id, :type => Integer

#pointsFixnum

Returns the points awarded to the grouping.

Returns:

  • (Fixnum)

    the points awarded to the grouping



16
# File 'lib/osm/grouping.rb', line 16

attribute :id, :type => Integer

#section_idFixnum

Returns the id for the section this grouping belongs to.

Returns:

  • (Fixnum)

    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

Parameters:

  • api (Osm::Api)

    The api to use to make the request

  • section (Fixnum)

    the section (or its ID) of the section to get groupings for

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :no_cache (Boolean) — default: optional

    if true then the data will be retreived from OSM not the cache

Returns:

  • (Array<Osm::Grouping>, nil)

    An array of groupings or nil if the user can not access that section



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/osm/grouping.rb', line 36

def self.get_for_section(api, section, options={})
  section_id = section.to_i
  cache_key = ['groupings', section_id]

  if !options[:no_cache] && cache_exist?(api, cache_key)
    return cache_read(api, cache_key)
  end

  data = api.perform_query("users.php?action=getPatrols&sectionid=#{section_id}")

  result = Array.new
  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)

  return result
end