Class: Jacoat::Document::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/jacoat/document/attribute.rb

Instance Method Summary collapse

Constructor Details

#initialize(arguments = {}) ⇒ Attributes

Returns a new instance of Attributes.



4
5
6
# File 'lib/jacoat/document/attribute.rb', line 4

def initialize(arguments = {})
  @hash = arguments
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/jacoat/document/attribute.rb', line 8

def method_missing(m, *args)
  #setter
  if /^(\w+)=$/ =~ m 
    @hash[:"#{$1}"] = args[0]
  end
  #getter
  @hash[:"#{m}"]
end

Instance Method Details

#to_hashObject



17
18
19
# File 'lib/jacoat/document/attribute.rb', line 17

def to_hash
  proc = Proc.new { |k, v| v.kind_of?(Hash) ? (v.delete_if(&proc); nil) : v.nil? }; @hash.delete_if(&proc)
end