Class: RememberTheMilkHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/thartmx_lib.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.



466
467
468
469
# File 'lib/thartmx_lib.rb', line 466

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



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/thartmx_lib.rb', line 491

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.



459
460
461
# File 'lib/thartmx_lib.rb', line 459

def rtm
  @rtm
end

Class Method Details

.strict_keys=(value) ⇒ Object



462
463
464
# File 'lib/thartmx_lib.rb', line 462

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



480
481
482
483
484
485
486
487
488
# File 'lib/thartmx_lib.rb', line 480

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



471
472
473
# File 'lib/thartmx_lib.rb', line 471

def id
  rtm_id || object_id
end

#rtm_idObject



475
476
477
# File 'lib/thartmx_lib.rb', line 475

def rtm_id
  self[:id]
end