Class: BasecampAPI::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/basecamp/basecamp.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, hash) ⇒ Record

Returns a new instance of Record.



398
399
400
# File 'lib/basecamp/basecamp.rb', line 398

def initialize(type, hash)
  @type, @hash = type, hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



429
430
431
432
433
434
435
# File 'lib/basecamp/basecamp.rb', line 429

def method_missing(sym, *args)
  if args.empty? && !block_given? && respond_to?(sym)
    self[sym]
  else
    super
  end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



396
397
398
# File 'lib/basecamp/basecamp.rb', line 396

def type
  @type
end

Instance Method Details

#[](name) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/basecamp/basecamp.rb', line 402

def [](name)
  name = dashify(name)

  case @hash[name]
  when Hash then 
    @hash[name] = if (@hash[name].keys.length == 1 && @hash[name].values.first.is_a?(Array))
                    @hash[name].values.first.map { |v| Record.new(@hash[name].keys.first, v) }
                  else
                    Record.new(name, @hash[name])
                  end
  else
    @hash[name]
  end
end

#attributesObject



421
422
423
# File 'lib/basecamp/basecamp.rb', line 421

def attributes
  @hash.keys
end

#idObject



417
418
419
# File 'lib/basecamp/basecamp.rb', line 417

def id
  @hash['id']
end

#inspectObject



441
442
443
# File 'lib/basecamp/basecamp.rb', line 441

def inspect
  to_s
end

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


425
426
427
# File 'lib/basecamp/basecamp.rb', line 425

def respond_to?(sym)
  super || @hash.has_key?(dashify(sym))
end

#to_sObject



437
438
439
# File 'lib/basecamp/basecamp.rb', line 437

def to_s
  "\#<Record(#{@type}) #{@hash.inspect[1..-2]}>"
end