Class: IMW::Metadata::Field
Overview
Conceptually, a field is a “slot” for which “records” can have values.
An IMW::Metadata::Field is essentially a Hash that has one required property: a name.
IMW::Metadata::Field.new('id')
#=> { 'name' => 'id' }
But you can declare as many other properties as you want (as long as you include a name):
IMW::Metadata::Field.new 'name' => 'id', 'type' => :integer, 'title' => "ID", 'description' => "Auto-incremented."
#=> { 'name' => 'id', 'type' => :integer, 'title' > "ID", 'description' => "Auto-incremented." }
Instance Method Summary collapse
-
#initialize(obj) ⇒ Field
constructor
A new instance of Field.
- #titleize ⇒ Object
Methods inherited from Hash
#assoc, #compact, #compact!, #deep_merge, #deep_merge!, #dispatch, #emit, #from_pairs, #keep_merge, #quote_keys_with, #rassoc, #reverse_merge, #reverse_merge!, #slice, #slice!, #terminals, #to_openstruct, zip
Constructor Details
#initialize(obj) ⇒ Field
Returns a new instance of Field.
21 22 23 24 25 26 27 28 29 |
# File 'lib/imw/metadata/field.rb', line 21 def initialize obj super() if obj.is_a?(Hash) || obj.is_a?(Field) merge!(obj) raise IMW::ArgumentError.new("A field must have a name") if obj['name'].blank? else self['name'] = obj.to_s.strip end end |
Instance Method Details
#titleize ⇒ Object
31 32 33 |
# File 'lib/imw/metadata/field.rb', line 31 def titleize self['title'] || self['name'].capitalize # FIXME we can do better than this! end |