Sha256: a4d739db10f06261e1161068edc0ae30c08c0fe050e18e29ed56a5660c029df4
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
module IMW class Metadata # 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." } class Field < Hash 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 def titleize self['title'] || self['name'].capitalize # FIXME we can do better than this! end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
imw-0.2.18 | lib/imw/metadata/field.rb |
imw-0.2.17 | lib/imw/metadata/field.rb |