Class: XRBP::NodeStore::STObject

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/xrbp/nodestore/sle/st_object.rb

Overview

Seralized Type containing fields associated with ids

Direct Known Subclasses

STLedgerEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ STObject

Returns a new instance of STObject.


12
13
14
15
16
17
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 12

def initialize(args={})
  @item = args[:item]

  @fields, remaining = parse_fields(item.data)
  raise unless remaining.size == 0
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields


10
11
12
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 10

def fields
  @fields
end

#itemObject (readonly)

Returns the value of attribute item


10
11
12
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 10

def item
  @item
end

Instance Method Details

#account_id(field) ⇒ Object


41
42
43
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 41

def (field)
  field(STAccount, field)
end

#amount(field) ⇒ Object


37
38
39
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 37

def amount(field)
  field(STAmount, field)
end

#field(type, id) ⇒ Object


32
33
34
35
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 32

def field(type, id)
  fields[id]
  # type should already be converted in parsing process (TODO verify?)
end

#field?(id) ⇒ Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 28

def field?(id)
  fields.key?(id)
end

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)

23
24
25
26
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 23

def flag?(flag)
  flag = NodeStore::Format::SERIALIZED_FLAGS[flag] if flag.is_a?(Symbol)
  flags & flag == flag
end

#flagsObject


19
20
21
# File 'lib/xrbp/nodestore/sle/st_object.rb', line 19

def flags
  @flags ||= fields[:flags]
end