Class: GlobalPhone::Record

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/global_phone/record.rb

Direct Known Subclasses

Format, Region, Territory

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Record

Returns a new instance of Record.



22
23
24
# File 'lib/global_phone/record.rb', line 22

def initialize(data)
  @data = data
end

Class Method Details

.field(index, name, options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/global_phone/record.rb', line 7

def self.field(index, name, options = {}, &block)
  if block
    transform_method_name = :"transform_field_#{name}"
    define_method(transform_method_name, block)
  end

  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def #{name}
      value = @data[#{index.inspect}]
      #{"value = #{transform_method_name}(value) if value" if block}
      value #{"|| #{options[:fallback]}" if options[:fallback]}
    end
  RUBY
end