Class: JSON2Ruby::Attribute
- Inherits:
-
Object
- Object
- JSON2Ruby::Attribute
- Defined in:
- lib/json2ruby/attribute.rb
Overview
The Attribute class represents a field on an Entity - i.e. A field name and associated type.
Instance Attribute Summary collapse
-
#name ⇒ Object
The String name of the Attribute.
-
#original_name ⇒ Object
The original String name of the Array in the JSON ([^A-Za-z0-9_] are replaced with ‘_’).
-
#ruby_type ⇒ Object
The type of the attribute, i.e.
Class Method Summary collapse
-
.short_name ⇒ Object
The short name is ‘Attribute’.
Instance Method Summary collapse
-
#==(other) ⇒ Object
An Attribute is equal to another if and only if its attr_hash value is the same.
-
#attr_hash ⇒ Object
Return the MD5 hash of the name and the type.
-
#initialize(name, ruby_type = nil) ⇒ Attribute
constructor
Create a new attribute with the supplied String name and optional String type name.
Constructor Details
#initialize(name, ruby_type = nil) ⇒ Attribute
Create a new attribute with the supplied String name and optional String type name. If the type is not supplied or nil, if will be assigned ‘_unknown’
20 21 22 23 |
# File 'lib/json2ruby/attribute.rb', line 20 def initialize(name, ruby_type = nil) @name = name @ruby_type = ruby_type || "_unknown" end |
Instance Attribute Details
#name ⇒ Object
The String name of the Attribute
7 8 9 |
# File 'lib/json2ruby/attribute.rb', line 7 def name @name end |
#original_name ⇒ Object
The original String name of the Array in the JSON ([^A-Za-z0-9_] are replaced with ‘_’)
9 10 11 |
# File 'lib/json2ruby/attribute.rb', line 9 def original_name @original_name end |
#ruby_type ⇒ Object
The type of the attribute, i.e. a Entity, Collection or Primitive instance
11 12 13 |
# File 'lib/json2ruby/attribute.rb', line 11 def ruby_type @ruby_type end |
Class Method Details
.short_name ⇒ Object
The short name is ‘Attribute’
14 15 16 |
# File 'lib/json2ruby/attribute.rb', line 14 def self.short_name "Attribute" end |
Instance Method Details
#==(other) ⇒ Object
An Attribute is equal to another if and only if its attr_hash value is the same.
31 32 33 34 |
# File 'lib/json2ruby/attribute.rb', line 31 def ==(other) return false if other.class != self.class attr_hash == other.attr_hash end |
#attr_hash ⇒ Object
Return the MD5 hash of the name and the type.
26 27 28 |
# File 'lib/json2ruby/attribute.rb', line 26 def attr_hash Digest::MD5.hexdigest("#{@name}:#{@ruby_type}") end |