Class: Neo4j::Shared::TypeConverters::EnumConverter
- Inherits:
-
Object
- Object
- Neo4j::Shared::TypeConverters::EnumConverter
- Defined in:
- lib/neo4j/shared/type_converters.rb
Instance Method Summary collapse
- #convert_type ⇒ Object
- #converted?(value) ⇒ Boolean
- #db_type ⇒ Object
-
#initialize(enum_keys, options) ⇒ EnumConverter
constructor
A new instance of EnumConverter.
- #supports_array? ⇒ Boolean
- #to_db(value) ⇒ Object
- #to_ruby(value) ⇒ Object (also: #call)
Constructor Details
#initialize(enum_keys, options) ⇒ EnumConverter
Returns a new instance of EnumConverter.
267 268 269 270 |
# File 'lib/neo4j/shared/type_converters.rb', line 267 def initialize(enum_keys, ) @enum_keys = enum_keys @options = end |
Instance Method Details
#convert_type ⇒ Object
284 285 286 |
# File 'lib/neo4j/shared/type_converters.rb', line 284 def convert_type Symbol end |
#converted?(value) ⇒ Boolean
272 273 274 |
# File 'lib/neo4j/shared/type_converters.rb', line 272 def converted?(value) value.is_a?(db_type) end |
#db_type ⇒ Object
280 281 282 |
# File 'lib/neo4j/shared/type_converters.rb', line 280 def db_type Integer end |
#supports_array? ⇒ Boolean
276 277 278 |
# File 'lib/neo4j/shared/type_converters.rb', line 276 def supports_array? true end |
#to_db(value) ⇒ Object
294 295 296 297 298 299 300 |
# File 'lib/neo4j/shared/type_converters.rb', line 294 def to_db(value) if value.is_a?(Array) value.map(&method(:to_db)) else @enum_keys[value.to_s.to_sym] || 0 end end |
#to_ruby(value) ⇒ Object Also known as: call
288 289 290 |
# File 'lib/neo4j/shared/type_converters.rb', line 288 def to_ruby(value) @enum_keys.key(value) unless value.nil? end |