Class: Linkage::FieldSet
- Inherits:
-
Hash
- Object
- Hash
- Linkage::FieldSet
- Defined in:
- lib/linkage/field_set.rb
Overview
Instance Attribute Summary collapse
-
#primary_key ⇒ Field
readonly
Primary key of this field set.
Instance Method Summary collapse
-
#[](key) ⇒ Field
Returns the value for
key
, wherekey
is matched in a case-insensitive manner. -
#fetch_key(key) ⇒ Symbol
Returns a key that matches the parameter in a case-insensitive manner.
-
#has_key?(key) ⇒ Boolean
Returns whether or not
key
is contained in the field set (case-insensitive). -
#initialize(dataset) ⇒ FieldSet
constructor
Create a new FieldSet.
Constructor Details
#initialize(dataset) ⇒ FieldSet
Create a new FieldSet.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/linkage/field_set.rb', line 14 def initialize(dataset) dataset.schema.each do |(name, column_schema)| field = Field.new(name, column_schema) self[name] = field if @primary_key.nil? && column_schema[:primary_key] @primary_key = field end end end |
Instance Attribute Details
#primary_key ⇒ Field (readonly)
Returns primary key of this field set.
9 10 11 |
# File 'lib/linkage/field_set.rb', line 9 def primary_key @primary_key end |
Instance Method Details
#[](key) ⇒ Field
Returns the value for key
, where key
is matched in a case-insensitive
manner.
48 49 50 51 |
# File 'lib/linkage/field_set.rb', line 48 def [](key) k = fetch_key(key) k ? super(k) : nil end |
#fetch_key(key) ⇒ Symbol
Returns a key that matches the parameter in a case-insensitive manner.
38 39 40 41 |
# File 'lib/linkage/field_set.rb', line 38 def fetch_key(key) string_key = key.to_s keys.detect { |k| k.to_s.casecmp(string_key) == 0 } end |
#has_key?(key) ⇒ Boolean
Returns whether or not key
is contained in the field set
(case-insensitive).
30 31 32 |
# File 'lib/linkage/field_set.rb', line 30 def has_key?(key) !fetch_key(key).nil? end |