Class: RememberTheMilkHash

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

Overview

a standard hash with some helper methods

Direct Known Subclasses

RememberTheMilkTask

Constant Summary collapse

@@strict_keys =
true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rtm_object = nil) ⇒ RememberTheMilkHash

Returns a new instance of RememberTheMilkHash.



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

def initialize(rtm_object = nil)
  super
  @rtm = rtm_object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args) ⇒ Object



465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/rtmapi.rb', line 465

def method_missing( key, *args )
  name = key.to_s
  
  setter = false
  if name[-1,1] == '='
    name = name.chop
    setter = true
  end

  if name == ""
    name = "rtm_nil".to_sym
  else
    name = name.to_sym
  end
  
  
  # TODO: should we allow the blind setting of values? (i.e., only do this test
  #  if setter==false )
  raise "unknown hash key<#{name}> requested for #{self.inspect}" if @@strict_keys && !self.has_key?(name)
  
  if setter
    self[name] = *args
  else
    self[name]
  end
end

Instance Attribute Details

#rtmObject

Returns the value of attribute rtm.



433
434
435
# File 'lib/rtmapi.rb', line 433

def rtm
  @rtm
end

Class Method Details

.strict_keys=(value) ⇒ Object



436
437
438
# File 'lib/rtmapi.rb', line 436

def self.strict_keys=( value )
  @@strict_keys = value
end

Instance Method Details

#arrayify_value(key) ⇒ Object

guarantees that a given key corresponds to an array, even if it’s an empty array



454
455
456
457
458
459
460
461
462
# File 'lib/rtmapi.rb', line 454

def arrayify_value( key )
  if !self.has_key?(key)
    self[key] = []
  elsif self[key].class != Array
    self[key] = [ self[key] ].compact
  else
    self[key]
  end
end

#idObject



445
446
447
# File 'lib/rtmapi.rb', line 445

def id
  rtm_id || object_id
end

#rtm_idObject



449
450
451
# File 'lib/rtmapi.rb', line 449

def rtm_id
  self[:id]
end