Class: MessageBird::Base
- Inherits:
-
Object
- Object
- MessageBird::Base
- Defined in:
- lib/messagebird/base.rb
Direct Known Subclasses
Balance, CallFlow, CallFlowStep, CallFlowStepOption, Contact, ContactReference, Conversation, ConversationChannel, ConversationMessage, ConversationWebhook, CustomDetails, Error, Formats, Group, GroupReference, HLR, List, Lookup, Message, MessageReference, Number, Recipient, Verify, VerifyEmailMessage, Voice::Base, Voice::Call, VoiceMessage
Instance Method Summary collapse
-
#initialize(json) ⇒ Base
constructor
A new instance of Base.
-
#map_hash_elements_to_self(hash) ⇒ Object
takes each element from the given hash and apply it to ourselves through an assignment method.
- #value_to_time(value) ⇒ Object
Constructor Details
#initialize(json) ⇒ Base
Returns a new instance of Base.
19 20 21 |
# File 'lib/messagebird/base.rb', line 19 def initialize(json) map_hash_elements_to_self(json) end |
Instance Method Details
#map_hash_elements_to_self(hash) ⇒ Object
takes each element from the given hash and apply it to ourselves through an assignment method
9 10 11 12 13 14 15 16 17 |
# File 'lib/messagebird/base.rb', line 9 def map_hash_elements_to_self(hash) return if hash.nil? hash.each do |key, value| method_name = key.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase # convert came case to snake case method_name += '=' send(method_name, value) if respond_to?(method_name) end end |
#value_to_time(value) ⇒ Object
23 24 25 |
# File 'lib/messagebird/base.rb', line 23 def value_to_time(value) value ? Time.parse(value) : nil end |