Class: Hyperion::FieldSpec
- Inherits:
-
Object
- Object
- Hyperion::FieldSpec
- Defined in:
- lib/hyperion.rb
Instance Attribute Summary collapse
-
#db_name ⇒ Object
readonly
Returns the value of attribute db_name.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, opts = {}) ⇒ FieldSpec
constructor
A new instance of FieldSpec.
- #pack(value) ⇒ Object
- #unpack(value) ⇒ Object
Constructor Details
#initialize(name, opts = {}) ⇒ FieldSpec
Returns a new instance of FieldSpec.
271 272 273 274 275 276 277 278 |
# File 'lib/hyperion.rb', line 271 def initialize(name, opts={}) @name = name @default = opts[:default] @type = opts[:type] @packer = opts[:packer] @unpacker = opts[:unpacker] @db_name = opts[:db_name] ? Format.format_field(opts[:db_name]) : name end |
Instance Attribute Details
#db_name ⇒ Object (readonly)
Returns the value of attribute db_name.
269 270 271 |
# File 'lib/hyperion.rb', line 269 def db_name @db_name end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
269 270 271 |
# File 'lib/hyperion.rb', line 269 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
269 270 271 |
# File 'lib/hyperion.rb', line 269 def name @name end |
Instance Method Details
#pack(value) ⇒ Object
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/hyperion.rb', line 280 def pack(value) if @packer && @packer.respond_to?(:call) @packer.call(value) elsif @type type_packer = Hyperion.packer_for(@type) type_packer ? type_packer.call(value) : value else value end end |
#unpack(value) ⇒ Object
291 292 293 294 295 296 297 298 299 300 |
# File 'lib/hyperion.rb', line 291 def unpack(value) if @unpacker && @unpacker.respond_to?(:call) @unpacker.call(value) elsif @type type_packer = Hyperion.unpacker_for(@type) type_packer ? type_packer.call(value) : value else value end end |