Class: RiceBubble::Attributes
- Inherits:
-
Object
- Object
- RiceBubble::Attributes
show all
- Includes:
- Enumerable
- Defined in:
- lib/rice_bubble/attributes.rb,
lib/rice_bubble/attributes/any.rb,
lib/rice_bubble/attributes/base.rb,
lib/rice_bubble/attributes/date.rb,
lib/rice_bubble/attributes/enum.rb,
lib/rice_bubble/attributes/time.rb,
lib/rice_bubble/attributes/array.rb,
lib/rice_bubble/attributes/number.rb,
lib/rice_bubble/attributes/object.rb,
lib/rice_bubble/attributes/string.rb,
lib/rice_bubble/attributes/boolean.rb,
lib/rice_bubble/attributes/integer.rb,
lib/rice_bubble/attributes/literal.rb,
lib/rice_bubble/attributes/datetime.rb,
lib/rice_bubble/attributes/optional.rb,
lib/rice_bubble/attributes/serialized.rb
Defined Under Namespace
Classes: Any, Array, Base, Boolean, Date, Datetime, Enum, Integer, Literal, Number, Object, Optional, Serialized, String, Time
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Attributes
Returns a new instance of Attributes.
7
8
9
10
11
12
|
# File 'lib/rice_bubble/attributes.rb', line 7
def initialize(attrs = {})
@attributes = {}
attrs.each do |name, attr|
self[name] = attr
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3
4
5
|
# File 'lib/rice_bubble/attributes.rb', line 3
def attributes
@attributes
end
|
Class Method Details
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rice_bubble/attributes.rb', line 45
def self.[](type)
@types ||= {}
@types[type] ||=
begin
class_name = type.to_s.gsub(/(^|_)(\w)/) do
::Regexp.last_match(2).upcase
end
Object.const_get "RiceBubble::Attributes::#{class_name}"
end
rescue NameError
nil
end
|
Instance Method Details
31
32
33
|
# File 'lib/rice_bubble/attributes.rb', line 31
def [](name)
attributes[name.to_sym]
end
|
#[]=(name, attr) ⇒ Object
35
36
37
|
# File 'lib/rice_bubble/attributes.rb', line 35
def []=(name, attr)
attributes[name] = attr
end
|
19
20
21
22
23
24
25
|
# File 'lib/rice_bubble/attributes.rb', line 19
def each(&)
if block_given?
attributes.each(&)
else
to_enum(:each)
end
end
|
#include?(name) ⇒ Boolean
27
28
29
|
# File 'lib/rice_bubble/attributes.rb', line 27
def include?(name)
attributes.key?(name.to_sym)
end
|
#initialize_copy(other) ⇒ Object
14
15
16
17
|
# File 'lib/rice_bubble/attributes.rb', line 14
def initialize_copy(other)
super
@attributes = other.attributes.dup
end
|
39
40
41
42
43
|
# File 'lib/rice_bubble/attributes.rb', line 39
def map(&)
attributes.keys.each.with_object({}) do |name, hash|
hash[name] = yield(name, attributes[name])
end
end
|