Class: Swift::Header

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/swift/header.rb

Instance Method Summary collapse

Constructor Details

#initialize(*attributes) ⇒ Header

Returns a new instance of Header.



5
6
7
8
# File 'lib/swift/header.rb', line 5

def initialize *attributes
  @attributes = {}
  push *attributes unless attributes.empty?
end

Instance Method Details

#allObject



26
27
28
# File 'lib/swift/header.rb', line 26

def all
  @all ||= @attributes.keys
end

#each(&block) ⇒ Object



40
41
42
# File 'lib/swift/header.rb', line 40

def each &block
  @attributes.values.each{|v| yield v}
end

#insertableObject



18
19
20
# File 'lib/swift/header.rb', line 18

def insertable
  @insertable ||= all - [serial]
end

#keysObject



36
37
38
# File 'lib/swift/header.rb', line 36

def keys
  @keys ||= select(&:key).map(&:field)
end

#new_tupleObject



10
11
12
# File 'lib/swift/header.rb', line 10

def new_tuple
  Hash[insertable.map{|field| [field, @attributes[field].default]}]
end

#push(*attributes) ⇒ Object



14
15
16
# File 'lib/swift/header.rb', line 14

def push *attributes
  @attributes.update Hash[attributes.map{|attribute| [attribute.field, attribute]}]
end

#serialObject



30
31
32
33
34
# File 'lib/swift/header.rb', line 30

def serial
  return @serial if defined? @serial
  serial  = find(&:serial)
  @serial = serial ? serial.field : nil
end

#updatableObject



22
23
24
# File 'lib/swift/header.rb', line 22

def updatable
  @updatable ||= all - (keys | [serial])
end