Class: Swift::Header
Instance Method Summary collapse
- #all ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(*attributes) ⇒ Header
constructor
A new instance of Header.
- #insertable ⇒ Object
- #keys ⇒ Object
- #new_tuple ⇒ Object
- #push(*attributes) ⇒ Object
- #serial ⇒ Object
- #updatable ⇒ Object
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
#all ⇒ Object
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 |
#insertable ⇒ Object
18 19 20 |
# File 'lib/swift/header.rb', line 18 def insertable @insertable ||= all - [serial] end |
#keys ⇒ Object
36 37 38 |
# File 'lib/swift/header.rb', line 36 def keys @keys ||= select(&:key).map(&:field) end |
#new_tuple ⇒ Object
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 |
#serial ⇒ Object
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 |
#updatable ⇒ Object
22 23 24 |
# File 'lib/swift/header.rb', line 22 def updatable @updatable ||= all - (keys | [serial]) end |