Sha256: cbb2d8e5aee53006053c68ba4921416e49f77517b2997f53e1dc498b29116ba6

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

module Osm

  class Grouping

    attr_reader :id, :name, :active, :points
    # @!attribute [r] id
    #   @return [Fixnum] the id for grouping
    # @!attribute [r] name
    #   @return [String] the name of the grouping
    # @!attribute [r] active
    #   @return [Boolean] wether the grouping is active
    # @!attribute [r] points
    #   @return [Fixnum] the points awarded to the grouping

    # Initialize a new Grouping
    # @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
    def initialize(attributes={})
      raise ArgumentError, ':id must be a Fixnum > 0' unless (attributes[:id].is_a?(Fixnum) && attributes[:id] > 0)
      raise ArgumentError, ':name must be a String' unless attributes[:name].is_a?(String)
      raise ArgumentError, ':active must be nil or a Boolean' unless attributes[:active].nil? || [true, false].include?(attributes[:active])
      raise ArgumentError, ':points must be nil or a Fixnum >= 0' unless attributes[:points].nil? || (attributes[:points].is_a?(Fixnum) && attributes[:points] >= 0)

      attributes.each { |k,v| instance_variable_set("@#{k}", v) }
    end


    # Initialize a new Grouping from api data
    # @param [Hash] data the hash of data provided by the API
    def self.from_api(data)
      new({
        :id => Osm::to_i_or_nil(data['patrolid']),
        :name => data['name'],
        :active => (data['active'] == 1),
        :points => Osm::to_i_or_nil(data['points']),
      })
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
osm-0.0.15 lib/osm/grouping.rb
osm-0.0.14 lib/osm/grouping.rb
osm-0.0.13 lib/osm/grouping.rb
osm-0.0.12 lib/osm/grouping.rb