Class: Perpetuity::Attribute
- Inherits:
-
Object
- Object
- Perpetuity::Attribute
- Defined in:
- lib/perpetuity/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #=~(regexp) ⇒ Object
- #embedded? ⇒ Boolean
-
#initialize(name, type = nil, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #options(option = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, type = nil, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
4 5 6 7 8 9 10 11 12 |
# File 'lib/perpetuity/attribute.rb', line 4 def initialize(name, type=nil, = {}) @name = name @type = type @_options = .dup .each do |option, value| instance_variable_set "@#{option}", value end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/perpetuity/attribute.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/perpetuity/attribute.rb', line 3 def type @type end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 37 |
# File 'lib/perpetuity/attribute.rb', line 34 def == other other.is_a?(self.class) && name.to_s == other.name.to_s end |
#=~(regexp) ⇒ Object
30 31 32 |
# File 'lib/perpetuity/attribute.rb', line 30 def =~ regexp name.to_s =~ regexp end |
#embedded? ⇒ Boolean
22 23 24 |
# File 'lib/perpetuity/attribute.rb', line 22 def @embedded ||= false end |
#options(option = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/perpetuity/attribute.rb', line 14 def option=nil if option instance_variable_get("@#{option}") else @_options end end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/perpetuity/attribute.rb', line 26 def to_s name.to_s end |