Class: E9Crm::LabeledString

Inherits:
String
  • Object
show all
Defined in:
lib/e9_crm/rails_extensions.rb

Overview

Simple string subclass that lets you query the string against a “label” it was initialized with. e.g.

LabeledString.new(:omfg, 'whatever').omfg? #=> true

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from String

#cents, #to_money

Constructor Details

#initialize(label, *args) ⇒ LabeledString

Returns a new instance of LabeledString.



76
77
78
79
# File 'lib/e9_crm/rails_extensions.rb', line 76

def initialize(label, *args)
  @label = label if label.is_a?(Symbol)
  super(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/e9_crm/rails_extensions.rb', line 81

def method_missing(method_name, *args)
  if @label && method_name.to_s[-1,1] == '?'
    method_name.to_s[0..-2] == @label.to_s
  else
    super
  end
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



74
75
76
# File 'lib/e9_crm/rails_extensions.rb', line 74

def label
  @label
end