Class: Perpetuity::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @name = name
  @type = type

  @_options = options.dup
  options.each do |option, value|
    instance_variable_set "@#{option}", value
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/perpetuity/attribute.rb', line 3

def name
  @name
end

#typeObject (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

Returns:

  • (Boolean)


22
23
24
# File 'lib/perpetuity/attribute.rb', line 22

def embedded?
  @embedded ||= false
end

#options(option = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/perpetuity/attribute.rb', line 14

def options option=nil
  if option
    instance_variable_get("@#{option}")
  else
    @_options
  end
end

#to_sObject



26
27
28
# File 'lib/perpetuity/attribute.rb', line 26

def to_s
  name.to_s
end