Class: TheCity::MetricMeasurementList
- Includes:
- Enumerable
- Defined in:
- lib/api/metric_measurement_list.rb
Instance Attribute Summary
Attributes inherited from ApiList
#current_page, #per_page, #total_entries, #total_pages
Instance Method Summary collapse
-
#[](index) ⇒ UserRole
Get the specified user role.
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#initialize(options = {}) ⇒ MetricMeasurementList
constructor
Constructor.
Methods inherited from ApiList
load, #next_page, #next_page!, #next_page?
Constructor Details
#initialize(options = {}) ⇒ MetricMeasurementList
Constructor.
Options:
:metric_id - The ID of the metric to load the measurements for. (required)
:page - The page number to get.
:reader - The Reader to use to load the data.
Examples:
MetricMeasurementList.new({:metric_id => 12345})
MetricMeasurementList.new({:metric_id => 12345, :page => 2})
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/api/metric_measurement_list.rb', line 22 def initialize( = {}) @options = @options[:page] ||= 1 @options[:reader] = TheCity::MetricMeasurementListReader.new(@options) if @options[:reader].nil? @json_data = @options[:reader].load_feed @total_entries = @json_data['total_entries'] @total_pages = @json_data['total_pages'] @per_page = @json_data['per_page'] @current_page = @json_data['current_page'] end |
Instance Method Details
#[](index) ⇒ UserRole
Get the specified user role.
40 41 42 |
# File 'lib/api/metric_measurement_list.rb', line 40 def [](index) MetricMeasurement.new( @json_data['measurements'][index] ) if @json_data['measurements'][index] end |
#each(&block) ⇒ Object
This method is needed for Enumerable.
46 47 48 |
# File 'lib/api/metric_measurement_list.rb', line 46 def each &block @json_data['measurements'].each{ |measurement| yield( MetricMeasurement.new(measurement) )} end |
#empty? ⇒ Boolean
Checks if the list is empty.
56 57 58 |
# File 'lib/api/metric_measurement_list.rb', line 56 def empty? @json_data['measurements'].empty? end |