Class: Aston::Attributes

Inherits:
Object
  • Object
show all
Defined in:
lib/aston.rb

Overview

Wrapper for attributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Attributes

Returns a new instance of Attributes.



13
14
15
# File 'lib/aston.rb', line 13

def initialize(data = {})
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/aston.rb', line 11

def data
  @data
end

Instance Method Details

#==(other) ⇒ Object



29
30
31
# File 'lib/aston.rb', line 29

def ==(other)
  other.is_a?(Attributes) && @data == other.data
end

#[](key) ⇒ Object



21
22
23
# File 'lib/aston.rb', line 21

def [](key)
  @data[key]
end

#[]=(key, value) ⇒ Object



25
26
27
# File 'lib/aston.rb', line 25

def []=(key, value)
  @data[key] = value
end

#sizeObject



33
34
35
# File 'lib/aston.rb', line 33

def size
  @data.size
end

#to_hashObject



17
18
19
# File 'lib/aston.rb', line 17

def to_hash
  @data
end

#to_json(opts = nil) ⇒ Object



41
42
43
# File 'lib/aston.rb', line 41

def to_json(opts = nil)
  @data.to_json(opts)
end

#to_sObject



37
38
39
# File 'lib/aston.rb', line 37

def to_s
  @data.map { |k, v| "#{k}='#{v}'" }.join(' ')
end