Class: Fast::Json::Serializer::Attr
- Inherits:
-
Object
- Object
- Fast::Json::Serializer::Attr
- Defined in:
- lib/fast/json/serializer/attr.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#column_name ⇒ Object
Returns the value of attribute column_name.
-
#format ⇒ Object
Returns the value of attribute format.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #calc_value(serializer, hash) ⇒ Object
-
#initialize(name, options, &block) ⇒ Attr
constructor
options can be - column_name, from which column to get value - format, method to be called on the value.
Constructor Details
#initialize(name, options, &block) ⇒ Attr
options can be
- column_name, from which column to get value
- format, method to be called on the value
10 11 12 13 14 15 |
# File 'lib/fast/json/serializer/attr.rb', line 10 def initialize(name, , &block) @name = name @block = block @column_name = [:column_name]&.to_s @format = [:format] end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
5 6 7 |
# File 'lib/fast/json/serializer/attr.rb', line 5 def block @block end |
#column_name ⇒ Object
Returns the value of attribute column_name.
5 6 7 |
# File 'lib/fast/json/serializer/attr.rb', line 5 def column_name @column_name end |
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/fast/json/serializer/attr.rb', line 5 def format @format end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/fast/json/serializer/attr.rb', line 5 def name @name end |
Instance Method Details
#calc_value(serializer, hash) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fast/json/serializer/attr.rb', line 17 def calc_value(serializer, hash) return block.call(serializer, hash) if block value = hash[column_name || name] format ? value.send(format) : value end |