Class: HaloWaypoint::Resource
- Inherits:
-
Object
- Object
- HaloWaypoint::Resource
- Defined in:
- lib/halo_waypoint/resource.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #assign_attributes(attributes) ⇒ Object
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
4 5 6 |
# File 'lib/halo_waypoint/resource.rb', line 4 def initialize(attributes = {}) assign_attributes(attributes) end |
Class Method Details
.string_to_key(string) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/halo_waypoint/resource.rb', line 18 def string_to_key(string) string = string.dup string.gsub!(/::/, '/') string.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') string.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') string.gsub!(/([a-z\d])([A-Z])/,'\1_\2') string.tr!("-", "_") string.downcase! string end |
Instance Method Details
#assign_attributes(attributes) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/halo_waypoint/resource.rb', line 8 def assign_attributes(attributes) attributes.each do |key, value| key = self.class.string_to_key(key) self.instance_variable_set("@#{key}", value) if respond_to?(key) end end |