Class: Mode::Connector::TypeMap
- Inherits:
-
Object
- Object
- Mode::Connector::TypeMap
- Includes:
- Enumerable
- Defined in:
- lib/mode/connector/type_map.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize ⇒ TypeMap
constructor
A new instance of TypeMap.
- #insert(row) ⇒ Object
- #type(value) ⇒ Object
- #type?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ TypeMap
Returns a new instance of TypeMap.
8 9 10 |
# File 'lib/mode/connector/type_map.rb', line 8 def initialize @types = {} end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
6 7 8 |
# File 'lib/mode/connector/type_map.rb', line 6 def types @types end |
Instance Method Details
#each(&block) ⇒ Object
12 13 14 15 16 |
# File 'lib/mode/connector/type_map.rb', line 12 def each(&block) types.each do |name, value| yield name, type?(name) end end |
#insert(row) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/mode/connector/type_map.rb', line 18 def insert(row) row.each do |name, value| types[name] ||= {} types[name][type(value)] ||= 1 end end |
#type(value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mode/connector/type_map.rb', line 25 def type(value) if value.kind_of?(Integer) :integer elsif value.kind_of?(Float) :number elsif value.kind_of?(Date) || value.kind_of?(Time) :datetime elsif value.kind_of?(TrueClass) || value.kind_of?(FalseClass) :boolean else :string end end |
#type?(name) ⇒ Boolean
39 40 41 42 |
# File 'lib/mode/connector/type_map.rb', line 39 def type?(name) keys = types[name].keys keys.compact.length == 1 ? keys.first : :string end |