Class: Railstar::Code

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Code.



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

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



102
103
104
105
106
107
108
109
# File 'lib/railstar/code_holder.rb', line 102

def method_missing(name, *args)
  case @type[name]
  when "integer"
    @data[name.to_sym].to_i
  else
    @data[name.to_sym]
  end
end

Instance Method Details

#data(key) ⇒ Object



94
95
96
# File 'lib/railstar/code_holder.rb', line 94

def data(key)
  @data[key.to_sym]
end

#positionObject



98
99
100
# File 'lib/railstar/code_holder.rb', line 98

def position
  @data[:position].to_i
end