Class: Codabel::Column
- Inherits:
-
Object
- Object
- Codabel::Column
- Defined in:
- lib/codabel/column.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(range, path, type, options) ⇒ Column
constructor
A new instance of Column.
- #length ⇒ Object
- #path_starts_with?(prefix) ⇒ Boolean
- #specifics?(data) ⇒ Boolean
- #to_coda(record) ⇒ Object
Constructor Details
#initialize(range, path, type, options) ⇒ Column
Returns a new instance of Column.
3 4 5 6 7 8 |
# File 'lib/codabel/column.rb', line 3 def initialize(range, path, type, ) @range = range @path = Array(path) @type = type @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/codabel/column.rb', line 12 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/codabel/column.rb', line 10 def path @path end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
9 10 11 |
# File 'lib/codabel/column.rb', line 9 def range @range end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/codabel/column.rb', line 11 def type @type end |
Instance Method Details
#length ⇒ Object
14 15 16 |
# File 'lib/codabel/column.rb', line 14 def length range.size end |
#path_starts_with?(prefix) ⇒ Boolean
24 25 26 27 |
# File 'lib/codabel/column.rb', line 24 def path_starts_with?(prefix) prefix = Array(prefix) @path[0...prefix.size] == prefix end |
#specifics?(data) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/codabel/column.rb', line 29 def specifics?(data) return false if path.empty? !!data.dig(*path) end |
#to_coda(record) ⇒ Object
18 19 20 21 22 |
# File 'lib/codabel/column.rb', line 18 def to_coda(record) value = record.data.dig(*path) unless path.empty? value = [:default] if value.nil? type.to_coda(value, length) end |