Sha256: 0c8a370dcb9662c6c2662e4b2a82754ffccfc8ada97bf623dcf8e8f4234d3994
Contents?: true
Size: 1.63 KB
Versions: 12
Compression:
Stored size: 1.63 KB
Contents
module TheCity class TerminologyList < ApiList include Enumerable # Constructor. # # @param options A hash of options for loading the list. # # Options: # :page - The page number to get. # :reader - The Reader to use to load the data. # # # Examples: # TerminologyList.new # # TerminologyList.new({:page => 2}) # def initialize(options = {}) @options = options @options[:page] ||= 1 @options[:reader] = TheCity::TerminologyListReader.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 # All the terms in the list. # # @return array of term names. def all_labels return [] if @json_data['labels'].nil? @json_data['labels'].collect { |label| label.values[0] } end alias :labels :all_labels # Get the specified tag. # # @param index The index of the tag to get. # # @return [Tag] def [](index) Terminology.new( @json_data['labels'][index] ) if @json_data['labels'][index] end # This method is needed for Enumerable. def each &block @json_data['labels'].each{ |tag| yield( Terminology.new(tag) )} end # Alias the count method alias :size :count # Checks if the list is empty. # # @return True on empty, false otherwise. def empty? @json_data['labels'].empty? end end end
Version data entries
12 entries across 12 versions & 1 rubygems