Class: Jacoat::Document::Attributes
- Inherits:
-
Object
- Object
- Jacoat::Document::Attributes
- Defined in:
- lib/jacoat/document/attribute.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(arguments = {}) ⇒ Attributes
constructor
A new instance of Attributes.
- #method_missing(m, *args) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(arguments = {}) ⇒ Attributes
Returns a new instance of Attributes.
10 11 12 |
# File 'lib/jacoat/document/attribute.rb', line 10 def initialize(arguments = {}) @hash = arguments end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/jacoat/document/attribute.rb', line 14 def method_missing(m, *args) #setter if /^(\w+)=$/ =~ m @hash[:"#{$1}"] = args[0] end #getter @hash[:"#{m}"] end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
4 5 6 |
# File 'lib/jacoat/document/attribute.rb', line 4 def hash @hash end |
Class Method Details
.from_jsonapi(arguments = {}) ⇒ Object
6 7 8 |
# File 'lib/jacoat/document/attribute.rb', line 6 def self.from_jsonapi(arguments = {}) Attributes.new(arguments) end |
Instance Method Details
#to_hash ⇒ Object
23 24 25 |
# File 'lib/jacoat/document/attribute.rb', line 23 def to_hash proc = Proc.new { |k, v| v.kind_of?(Hash) ? (v.delete_if(&proc); nil) : v.nil? }; @hash.delete_if(&proc) end |