Class: Scale::Types::Metadata

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/metadata/metadata.rb

Instance Attribute Summary collapse

Attributes included from Base

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, included, #initialize, #to_human

Instance Attribute Details

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/metadata/metadata.rb', line 5

def version
  @version
end

Class Method Details

.decode(scale_bytes) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/metadata/metadata.rb', line 6

def self.decode(scale_bytes)
  bytes = scale_bytes.get_next_bytes(4)
  if bytes.bytes_to_utf8 == "meta"
    version_enum = {
      "type" => "enum",
      "value_list" => %w[MetadataV0 MetadataV1 MetadataV2 MetadataV3 MetadataV4 MetadataV5 MetadataV6 MetadataV7 MetadataV8 MetadataV9 MetadataV10 MetadataV11 MetadataV12 MetadataV13]
    }
     = Scale::Types.get(version_enum).decode(scale_bytes).value
     = Metadata.new "Scale::Types::#{}".constantize2.decode(scale_bytes)
    .version = [9..].to_i
  else
    scale_bytes.reset_offset
     = Scale::Types::MetadataV0.decode(scale_bytes)
     = Metadata.new 
    .version = 0
  end
  
end

Instance Method Details

#get_module(module_name) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/metadata/metadata.rb', line 25

def get_module(module_name)
  modules = self.value.value[:metadata][:modules]
  modules.each do |m|
    if m[:name].downcase == module_name.downcase
      return m
    end
  end
end

#get_module_call(module_name, call_name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/metadata/metadata.rb', line 34

def get_module_call(module_name, call_name)
  the_module = get_module(module_name)
  the_module[:calls].each do |call|
    if call[:name].downcase == call_name.downcase
      return call
    end
  end
end

#get_module_storage(module_name, storage_name) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/metadata/metadata.rb', line 43

def get_module_storage(module_name, storage_name)
  the_module = get_module(module_name)
  if the_module[:storage].class == Array
    storages = the_module[:storage]
  else
    storages = the_module[:storage][:items]
  end
  storages.find {|storage| storage[:name] == storage_name}
end