Class: CartoDB::Types::Metadata
- Inherits:
-
Hash
- Object
- Hash
- CartoDB::Types::Metadata
show all
- Defined in:
- lib/cartodb-rb-client/cartodb/types/metadata.rb
Constant Summary
collapse
- RESERVED_WORDS =
%w(
alias and BEGIN begin break case class def defined? do else elsif END end
ensure false for if in module next nil not or redo rescue retry return self
super then true undef unless until when while yield
)
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/cartodb-rb-client/cartodb/types/metadata.rb', line 42
def method_missing(name, *args, &block)
if name.to_s.end_with?('=') && args.size == 1
key = name.to_s[0...-1]
self[key.to_sym] = args[0]
else
super
end
end
|
Class Method Details
.from_hash(hash = {}) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/cartodb-rb-client/cartodb/types/metadata.rb', line 12
def from_hash(hash = {})
metadata = self.new
hash.each do |key, value|
metadata[key.to_sym] = value
end
metadata
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cartodb-rb-client/cartodb/types/metadata.rb', line 22
def []=(key, value)
key = :"#{key}_" if RESERVED_WORDS.include?(key.to_s)
if key.to_s.eql?('the_geom')
value = _geometry_features(value)
else
value = cast_value(value) unless CartoDB::Settings[:type_casting] == false
end
self.class.send :define_method, "#{key}" do
self[key.to_sym]
end
self.class.send :define_method, "#{key}=" do |value|
self[key.to_sym] = value
end
super(key, value)
end
|