Module: SML::Helpers

Defined in:
lib/ruby-sml/helpers.rb

Class Method Summary collapse

Class Method Details

.hex_to_s(hex) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/ruby-sml/helpers.rb', line 11

def self.hex_to_s(hex)
  result = ""
  hex.each_byte do |byte|
    result << byte.to_s(16) << ":"
  end
  result.slice!(-1)

  return result
end

.print_entry(entry) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby-sml/helpers.rb', line 21

def self.print_entry(entry)
  return unless (entry.class == SML::ListEntry or entry.class == SML::PeriodEntry)

  name = entry.name
  value = entry.value
  scaler = entry.scaler
  unit = entry.unit

  name = SML::OBIS::resolve(name)
  value = value * (10**entry.scaler) if ((value.class == Fixnum) and not (scaler.nil?))
  value = value.to_f if (value.class == Fixnum)
  unit = SML::Units[unit]["unit"] unless (unit.nil? or SML::Units[unit].nil?)

  puts "#{name}: #{value} #{unit}"
end


37
38
39
40
# File 'lib/ruby-sml/helpers.rb', line 37

def self.print_tree(tree)
  return unless tree.class == SML::Tree
  print_tree_internal(tree, 0)
end


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ruby-sml/helpers.rb', line 41

def self.print_tree_internal(tree, level)
  name = tree.parameter_name
  name = SML::OBIS::resolve(name)

  if level > 0
    (level*4).times do print " " end
    print "|-> " unless level == 0
  end
  puts "#{name} : #{tree.parameter_value}"

  tree.child_list.each do |child|
    print_tree_internal(child, level+1)
  end
end