Class: Railstar::Code

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

Instance Method Summary collapse

Constructor Details

#initialize(args, type = {}) ⇒ Code

Returns a new instance of Code.



89
90
91
92
93
# File 'lib/code_holder.rb', line 89

def initialize(args, type={})
  @data = Hash[*args]
  @type = type
  super(@data[:value])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



109
110
111
# File 'lib/code_holder.rb', line 109

def method_missing(name, *args)
  self.data(name)
end

Instance Method Details

#data(key = nil) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/code_holder.rb', line 95

def data(key=nil)
  return @data if key.nil?
  case @type[key]
  when "integer"
    @data[key.to_sym].to_i
  else
    @data[key.to_sym]
  end
end

#positionObject



105
106
107
# File 'lib/code_holder.rb', line 105

def position
  @data[:position].to_i
end

#valueObject



113
114
115
# File 'lib/code_holder.rb', line 113

def value
  self.data(:value)
end