Class: Mambu::ApiModel
- Inherits:
-
Object
show all
- Defined in:
- lib/mambu/api_model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ ApiModel
Returns a new instance of ApiModel.
3
4
5
6
7
8
|
# File 'lib/mambu/api_model.rb', line 3
def initialize(data)
data.each do |method_name, value|
self.class.send(:attr_accessor, method_name) unless self.class.method_defined?(method_name)
send("#{method_name}=", convert_decimal(value))
end
end
|
Class Method Details
.api_uri ⇒ Object
14
15
16
|
# File 'lib/mambu/api_model.rb', line 14
def self.api_uri
name.demodulize.downcase.pluralize
end
|
.endpoint(connection) ⇒ Object
10
11
12
|
# File 'lib/mambu/api_model.rb', line 10
def self.endpoint(connection)
"#{connection.api_url}/#{api_uri}"
end
|
Instance Method Details
#convert_decimal(value) ⇒ Object
18
19
20
21
|
# File 'lib/mambu/api_model.rb', line 18
def convert_decimal(value)
return value unless (value.is_a? String) && (value =~ /\A[-+]?[0-9]*\.?[0-9]+\Z/)
value.to_d
end
|