Class: Iqvoc::Origin

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

Defined Under Namespace

Modules: Filters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Origin

Returns a new instance of Origin.



113
114
115
116
# File 'lib/iqvoc/origin.rb', line 113

def initialize(value)
  self.initial_value = value.to_s
  self.value = initial_value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/iqvoc/origin.rb', line 128

def method_missing(meth, *args)
  if Filters.registered.keys.include?(meth.to_sym)
    Filters.registered[meth.to_sym].new.call(self, value)
  else
    super
  end
end

Instance Attribute Details

#filtersObject

Returns the value of attribute filters.



111
112
113
# File 'lib/iqvoc/origin.rb', line 111

def filters
  @filters
end

#initial_valueObject

Returns the value of attribute initial_value.



111
112
113
# File 'lib/iqvoc/origin.rb', line 111

def initial_value
  @initial_value
end

#valueObject

Returns the value of attribute value.



111
112
113
# File 'lib/iqvoc/origin.rb', line 111

def value
  @value
end

Instance Method Details

#inspectObject



142
143
144
# File 'lib/iqvoc/origin.rb', line 142

def inspect
  "#<Iqvoc::Origin:0x%08x>" % object_id
end

#run_filters!Object



122
123
124
125
126
# File 'lib/iqvoc/origin.rb', line 122

def run_filters!
  Filters.registered.each do |key, filter_class|
    filter_class.new.call(self, value)
  end
end

#to_sObject



136
137
138
139
140
# File 'lib/iqvoc/origin.rb', line 136

def to_s
  return value if touched?
  run_filters!
  value
end

#touched?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/iqvoc/origin.rb', line 118

def touched?
  value != initial_value
end