Class: EasyAttributes::Value

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/easy_attributes.rb

Overview

EasyAttributes::Value - Experiment! Value Class for attribute values

Instance Method Summary collapse

Constructor Details

#initialize(definition, value) ⇒ Value

Usage: Value.new(definition, symbol_or_value)



433
434
435
436
437
438
439
440
441
# File 'lib/easy_attributes.rb', line 433

def initialize(definition, value)
  @definition = definition
  @attribute = @definition.attribute
  if value.is_a?(Symbol)
    @value = @definition.value_of(value)
  else
    @value = value
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Forward all other methods to the actual @value class



464
465
466
# File 'lib/easy_attributes.rb', line 464

def method_missing(method, *args)
  @value.send(method, *args)
end

Instance Method Details

#<=>(other) ⇒ Object

Compare with a defined symbol or another value. Required for Comparable



449
450
451
452
453
454
455
# File 'lib/easy_attributes.rb', line 449

def <=>(other)
  if other.is_a?(Symbol)
    @value <=> @definition.value_of(other)
  else
    @value <=> other
  end
end

#nextObject Also known as: succ

Returns the next value in the definition as a Value object



458
459
460
# File 'lib/easy_attributes.rb', line 458

def next
  Value.new(@definition.next(@value))
end

#to_symObject

Returns the symbolic name of this value



444
445
446
# File 'lib/easy_attributes.rb', line 444

def to_sym
  @definition.symbol_of(@value)
end